9 个版本 (破坏性更新)
0.8.0 | 2022年2月19日 |
---|---|
0.7.0 | 2022年2月13日 |
0.6.0 | 2022年2月11日 |
0.5.0 | 2022年2月8日 |
0.1.0 | 2022年2月3日 |
#2742 in 解析器实现
每月51次 下载
130KB
2.5K SLoC
deser-path
deser 的实验性扩展库,提供了路径包装功能。
lib.rs
:
此包提供了一个包装类型,它观察序列化过程,将当前序列化路径通信到 SerializerState
和 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