pub fn deserialize<CFG, R, T>(read: R) -> Result<T>Expand description
Deserialize a value of type T from a std::io::Read.
The CFG parameter controls the deserialization format and must match the configuration
used during serialization. It can be either:
Full: Expects struct field identifiers and enum variant identifiers as stringsSlim: Expects serialized data without identifiers, using indices for enum variants
ยงExample
This example demonstrates a complete round-trip serialization and deserialization:
use serde::{Serialize, Deserialize};
use postbag::{serialize, deserialize, cfg::Full};
#[derive(Serialize, Deserialize, Debug, PartialEq)]
struct Person {
name: String,
age: u32,
}
let original = Person {
name: "Alice".to_string(),
age: 30,
};
let mut buffer = Vec::new();
serialize::<Full, _, _>(&mut buffer, &original).unwrap();
let deserialized: Person = deserialize::<Full, _, _>(buffer.as_slice()).unwrap();
assert_eq!(original, deserialized);