miniconf

Trait 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 wrappers using this trait.

§Derive macro

See crate::TreeSerialize. The derive macro attributes are described in the TreeKey trait.

Required Methods§

Source

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: A Keys identifying the node.
  • ser: A Serializer 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.

Implementations on Foreign Types§

Source§

impl<T0: TreeSerialize> TreeSerialize for (T0,)

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T0: TreeSerialize, T1: TreeSerialize> TreeSerialize for (T0, T1)

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T0: TreeSerialize, T1: TreeSerialize, T2: TreeSerialize> TreeSerialize for (T0, T1, T2)

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T0: TreeSerialize, T1: TreeSerialize, T2: TreeSerialize, T3: TreeSerialize> TreeSerialize for (T0, T1, T2, T3)

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T0: TreeSerialize, T1: TreeSerialize, T2: TreeSerialize, T3: TreeSerialize, T4: TreeSerialize> TreeSerialize for (T0, T1, T2, T3, T4)

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T0: TreeSerialize, T1: TreeSerialize, T2: TreeSerialize, T3: TreeSerialize, T4: TreeSerialize, T5: TreeSerialize> TreeSerialize for (T0, T1, T2, T3, T4, T5)

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T0: TreeSerialize, T1: TreeSerialize, T2: TreeSerialize, T3: TreeSerialize, T4: TreeSerialize, T5: TreeSerialize, T6: TreeSerialize> TreeSerialize for (T0, T1, T2, T3, T4, T5, T6)

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T0: TreeSerialize, T1: TreeSerialize, T2: TreeSerialize, T3: TreeSerialize, T4: TreeSerialize, T5: TreeSerialize, T6: TreeSerialize, T7: TreeSerialize> TreeSerialize for (T0, T1, T2, T3, T4, T5, T6, T7)

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T: TreeSerialize + Copy> TreeSerialize for Cell<T>

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T: TreeSerialize> TreeSerialize for Bound<T>

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T: TreeSerialize> TreeSerialize for Option<T>

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T: TreeSerialize> TreeSerialize for &T

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T: TreeSerialize> TreeSerialize for &mut T

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T: TreeSerialize> TreeSerialize for RefCell<T>

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T: TreeSerialize> TreeSerialize for Range<T>

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T: TreeSerialize> TreeSerialize for RangeFrom<T>

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T: TreeSerialize> TreeSerialize for RangeInclusive<T>

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T: TreeSerialize> TreeSerialize for RangeTo<T>

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T: TreeSerialize, E: TreeSerialize> TreeSerialize for Result<T, E>

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Source§

impl<T: TreeSerialize, const N: usize> TreeSerialize for [T; N]

Source§

fn serialize_by_key<K, S>( &self, keys: K, ser: S, ) -> Result<usize, Error<S::Error>>
where K: Keys, S: Serializer,

Implementors§