Go to file
Thomas Bahn 17ffa65cb2 Replace StrAllocating with String type in function parameters
The key parameter of the insert functions are of type String now.
As insert requires ownership of its parameter `key` and StrAllocating
being gone in rust these functions now communicate that ownership
in their signature.

As a result &str must be converted into a String at the caller instead
of the callee.

The Trait ToOwned isn't an alternative as it's a generalized Clone.
StrAllocating simply has hidden an allocation or move.
2014-12-23 18:34:20 +01:00
benches Replace MoveItems and MoveEntries with IntoIter 2014-12-23 18:05:58 +01:00
serde2 Replace StrAllocating with String type in function parameters 2014-12-23 18:34:20 +01:00
serde_macros update to rust head 2014-12-17 23:00:05 -08:00
src Silence deprecation warnings 2014-12-23 18:05:58 +01:00
tests Rename Serializable to Serialize, Deserializable to Deserialize 2014-11-13 07:54:44 -08:00
.gitignore Updated non_snake_case and struct lifetimes for the latest Rust 2014-09-04 21:57:13 -04:00
.travis.yml Add cargo build to .travis 2014-09-07 01:54:57 -07:00
Cargo.toml update to rust HEAD, fix the tests 2014-12-13 16:55:42 -08:00
LICENSE Optimize serialization 2014-06-22 10:33:45 -04:00
LICENSE-APACHE Optimize serialization 2014-06-22 10:33:45 -04:00
LICENSE-MIT Optimize serialization 2014-06-22 10:33:45 -04:00
README.md Update README.md 2014-09-07 22:15:16 -07:00

Experimental Rust Serialization Library.

Build Status

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:

struct Foo {
    x: int,
    y: int,
}

libserialize's deserializer essentially asks for:

  • Is the next value a struct named "Foo"? If not, error.
  • Is the next field named "x"? If not, error.
  • Is the next value an "int"? If not, error.
  • Is the next field named "y"? If not, error.
  • Is the next value an "int"? If not, error.
  • Is the struct finished? If not, error.

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:

  • What is the next value type?
    • If a struct, parse a struct.
    • If an integer, parse an integer.
    • ...

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.