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
or crate::postcard
for convenient wrappers using this trait.
§Derive macro
See crate::TreeDeserialize
.
The derive macro 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::de::Deserializer::from_slice(b"7");
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.