pub trait TreeSerialize: TreeSchema {
// Required method
fn serialize_by_key<S: Serializer>(
&self,
keys: impl Keys,
ser: S,
) -> Result<S::Ok, SerdeError<S::Error>>;
}Expand description
Serialize a leaf node by its keys.
See also crate::json_core or crate::postcard for convenient wrappers using this trait.
§Derive macro
See crate::TreeSerialize.
The derive macro attributes are described in the TreeSchema trait.
Required Methods§
Sourcefn serialize_by_key<S: Serializer>(
&self,
keys: impl Keys,
ser: S,
) -> Result<S::Ok, SerdeError<S::Error>>
fn serialize_by_key<S: Serializer>( &self, keys: impl Keys, ser: S, ) -> Result<S::Ok, SerdeError<S::Error>>
Serialize a node by keys.
use miniconf::{IntoKeys, TreeSchema, TreeSerialize};
#[derive(TreeSchema, TreeSerialize)]
struct S {
foo: u32,
bar: [u16; 2],
};
let s = S {
foo: 9,
bar: [11, 3],
};
let mut buf = [0u8; 10];
let mut ser = serde_json_core::ser::Serializer::new(&mut buf);
s.serialize_by_key(["bar", "0"].into_keys(), &mut ser).unwrap();
let len = ser.end();
assert_eq!(&buf[..len], b"11");§Args
keys: AKeysidentifying the node.ser: ASerializerto to serialize the value.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.