Trait miniconf::TreeSerialize
source · pub trait TreeSerialize<const Y: usize = 1>: TreeKey<Y> {
// 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::JsonCoreSlash
or Postcard
for convenient
super traits with blanket implementations using this trait.
§Derive macro
crate::TreeSerialize
derives TreeSerialize
for structs with named fields and tuple structs.
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::{TreeSerialize, TreeKey};
#[derive(TreeKey, TreeSerialize)]
struct S {
foo: u32,
#[tree(depth=1)]
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_iter(), &mut ser).unwrap();
let len = ser.end();
assert_eq!(&buf[..len], b"11");
§Args
keys
: AnIterator
ofKey
s identifying the node.ser
: ASerializer
to to serialize the value.
§Returns
Node depth on success.
Object Safety§
This trait is not object safe.