pub trait TreeSerialize {
// Required method
fn serialize_by_key<K, S>(
&self,
keys: K,
ser: S,
) -> Result<usize, Error<S::Error>>
where K: Keys,
S: Serializer;
}
Expand description
Serialize a leaf node by its keys.
See also crate::json
or crate::postcard
for convenient wrappers using this trait.
§Derive macro
See crate::TreeSerialize
.
The derive macro attributes are described in the TreeKey
trait.
Required Methods§
Sourcefn serialize_by_key<K, S>(
&self,
keys: K,
ser: S,
) -> Result<usize, Error<S::Error>>where
K: Keys,
S: Serializer,
fn serialize_by_key<K, S>(
&self,
keys: K,
ser: S,
) -> Result<usize, Error<S::Error>>where
K: Keys,
S: Serializer,
Serialize a node by keys.
use miniconf::{IntoKeys, Leaf, TreeKey, TreeSerialize};
#[derive(TreeKey, TreeSerialize)]
struct S {
foo: Leaf<u32>,
bar: [Leaf<u16>; 2],
};
let s = S {
foo: 9.into(),
bar: [11.into(), 3.into()],
};
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
: AKeys
identifying the node.ser
: ASerializer
to to serialize the value.
§Returns
Node depth on success.
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.