Experimental Rust Serialization Library.
This is an experiment to modernize rust's libserialize
library. It is designed to implement https://github.com/rust-lang/rfcs/pull/22. rust-serde
is an attempt to address a major shortcoming in libserialize
. For normal structures, when you say you want to deserialize into:
rust
struct Foo {
x: int,
y: int,
}
libserialize
's deserializer essentially asks for:
While this works for user defined structures, it cannot support deserializing into a value like json::Json
, which is an enum that can represent every JSON value. In order to support that, it needs to be able to do some lookahead:
More formally, libserialize
implements a LL(0) grammar, whereas json::Json
requires a LL(1) grammar. rust-serde
provides this by implementing a serializer and deserializer that produces a tagged token stream of values. This enables a Deserializable
for json::Json
to look at the next token before deciding on how to parse the value.
There is now also a new library variation called serde2
. This removes the need for tagged values and replaces them with a Visitor
pattern. This pattern is very similar to the Iterator
pattern, but it threads some custom state through visiting each type. This gets many of the benefits of the serde
library without needing to always pay for tagging the variants.