Trait miniconf::TreeSerialize
source · 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 functions using these traits.
§Derive macro
crate::TreeSerialize
derives TreeSerialize
for structs with named fields and tuple structs
and for enums with newtype and unit variants.
The field 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.
Object Safety§
This trait is not object safe.