Trait miniconf::TreeDeserialize
source · pub trait TreeDeserialize<'de> {
// Required method
fn deserialize_by_key<K, D>(
&mut self,
keys: K,
de: D,
) -> Result<usize, Error<D::Error>>
where K: Keys,
D: Deserializer<'de>;
}
Expand description
Deserialize a leaf node by its keys.
See also crate::json
for a convenient helper functions using this trait.
§Derive macro
crate::TreeDeserialize
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 deserialize_by_key<K, D>(
&mut self,
keys: K,
de: D,
) -> Result<usize, Error<D::Error>>where
K: Keys,
D: Deserializer<'de>,
fn deserialize_by_key<K, D>(
&mut self,
keys: K,
de: D,
) -> Result<usize, Error<D::Error>>where
K: Keys,
D: Deserializer<'de>,
Deserialize a leaf node by its keys.
use miniconf::{IntoKeys, Leaf, TreeDeserialize, TreeKey};
#[derive(Default, TreeKey, TreeDeserialize)]
struct S {
foo: Leaf<u32>,
bar: [Leaf<u16>; 2],
};
let mut s = S::default();
let mut de = serde_json_core::de::Deserializer::new(b"7", None);
s.deserialize_by_key(["bar", "0"].into_keys(), &mut de)
.unwrap();
de.end().unwrap();
assert_eq!(*s.bar[0], 7);
§Args
keys
: AKeys
identifying the node.de
: ADeserializer
to deserialize the value.
§Returns
Node depth on success
Object Safety§
This trait is not object safe.