Crates.io | serde-content |
lib.rs | serde-content |
version | 0.1.0 |
source | src |
created_at | 2024-07-18 01:36:16.610441 |
updated_at | 2024-08-05 16:16:05.21051 |
description | Rust data structures for the Serde data model |
homepage | |
repository | https://github.com/rushmorem/serde-content |
max_upload_size | |
id | 1306827 |
size | 182,957 |
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
.
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(())
}