9 releases (breaking)

0.8.0 Feb 19, 2022
0.7.0 Feb 13, 2022
0.6.0 Feb 11, 2022
0.5.0 Feb 8, 2022
0.1.0 Feb 3, 2022

#109 in #deserialization

Apache-2.0

130KB
2.5K SLoC

deser-path

Experimental extension library to deser that provides path wrapping.


lib.rs:

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

Dependencies