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§

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.

Object Safety§

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§