Crate deser_path
source · [−]Expand description
This crate provides a wrapper type that observes the serialization to communicate
the current path of the serialization into the SerializerState
and DeserializerState
.
use deser_path::{Path, PathSerializable};
use deser::ser::{Serialize, SerializerState, Chunk};
use deser::{Atom, Error};
struct MyInt(u32);
impl Serialize for MyInt {
fn serialize(&self, state: &SerializerState) -> Result<Chunk, Error> {
// for as long as we're wrapped with the `PathSerializable` we can at
// any point request the current path from the state.
let path = state.get::<Path>();
println!("{:?}", path.segments());
self.0.serialize(state)
}
}
let serializable = vec![MyInt(42), MyInt(23)];
let path_serializable = PathSerializable::wrap(&serializable);
// now serialize path_serializable instead
Structs
The current path of the serialization.
Wraps a serializable so that it tracks the current path.
A path sink tracks the current path during deserialization.
Enums
A single segment in the path.