2 unstable releases

0.1.0 Aug 5, 2024
0.0.0 Jul 18, 2024

#279 in Encoding

Download history 318/week @ 2024-08-03 1147/week @ 2024-08-10 1552/week @ 2024-08-17 1339/week @ 2024-08-24 1670/week @ 2024-08-31 1618/week @ 2024-09-07 2119/week @ 2024-09-14 2728/week @ 2024-09-21 2384/week @ 2024-09-28 2107/week @ 2024-10-05 2313/week @ 2024-10-12 2716/week @ 2024-10-19 2565/week @ 2024-10-26 2860/week @ 2024-11-02 3491/week @ 2024-11-09 4500/week @ 2024-11-16

13,773 downloads per month
Used in 36 crates (9 directly)

MIT/Apache

130KB
4K SLoC

Serde data model

serde-content is an alternative design for the private Serde content types like this one. These types are used to store the Rust values that represent the Serde data model. The model is stable and well documented.

This crate offers a unified design for both serialising and deserialising data. The goal is to offer a stable interface with roundtrip guarantees when serialising to and deserialising from Value using our Serializer and Deserializer.

Example

use serde::{Deserialize, Serialize};
use serde_content::{Deserializer, Serializer};

#[derive(Debug, Serialize, Deserialize)]
struct Point {
    x: i32,
    y: i32,
}

fn main() -> serde_content::Result<()> {
    let point = Point { x: 1, y: 2 };

    // Convert the Point to the Value type.
    let serialized = Serializer::new().serialize(&point)?;

    // Pretty print the serialised Value.
    dbg!(&serialized);

    // Convert the Value back to a Point.
    let deserialized: Point = Deserializer::new(serialized).deserialize()?;

    // Pretty print the deserialised Point.
    dbg!(deserialized);

    Ok(())
}

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in Serde by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~155KB