Skip to main content

FromFlattened

Trait FromFlattened 

Source
pub trait FromFlattened<'de>: Sized {
    type Partial;

    // Required methods
    fn init() -> Self::Partial;
    fn insert(
        ctx: &mut Context<'de>,
        key: &Key<'de>,
        item: &Item<'de>,
        partial: &mut Self::Partial,
    ) -> Result<(), Failed>;
    fn finish(
        ctx: &mut Context<'de>,
        parent: &Table<'de>,
        partial: Self::Partial,
    ) -> Result<Self, Failed>;
}
Available on crate feature from-toml only.
Expand description

Trait for types that can be constructed from flattened TOML table entries.

Used with #[toml(flatten)] on struct fields. Built-in implementations cover HashMap and BTreeMap.

If your type implements FromToml, use #[toml(flatten, with = flatten_any)] in your derive instead of implementing this trait. See helper::flatten_any.

Required Associated Types§

Source

type Partial

Intermediate accumulator type used during conversion.

Required Methods§

Source

fn init() -> Self::Partial

Creates an empty accumulator to collect flattened entries.

Source

fn insert( ctx: &mut Context<'de>, key: &Key<'de>, item: &Item<'de>, partial: &mut Self::Partial, ) -> Result<(), Failed>

Inserts a single key-value pair into the accumulator.

Source

fn finish( ctx: &mut Context<'de>, parent: &Table<'de>, partial: Self::Partial, ) -> Result<Self, Failed>

Converts the accumulator into the final value after all entries have been inserted. The parent parameter is the table that contained the flattened entries.

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<'de, K, V> FromFlattened<'de> for BTreeMap<K, V>
where K: Ord + FromToml<'de>, V: FromToml<'de>,

Source§

type Partial = BTreeMap<K, V>

Source§

fn init() -> Self

Source§

fn insert( ctx: &mut Context<'de>, key: &Key<'de>, item: &Item<'de>, partial: &mut Self::Partial, ) -> Result<(), Failed>

Source§

fn finish( _ctx: &mut Context<'de>, _parent: &Table<'de>, partial: Self::Partial, ) -> Result<Self, Failed>

Source§

impl<'de, K, V, H> FromFlattened<'de> for HashMap<K, V, H>
where K: Hash + Eq + FromToml<'de>, V: FromToml<'de>, H: Default + BuildHasher,

Source§

type Partial = HashMap<K, V, H>

Source§

fn init() -> Self

Source§

fn insert( ctx: &mut Context<'de>, key: &Key<'de>, item: &Item<'de>, partial: &mut Self::Partial, ) -> Result<(), Failed>

Source§

fn finish( _ctx: &mut Context<'de>, _parent: &Table<'de>, partial: Self::Partial, ) -> Result<Self, Failed>

Implementors§

Source§

impl<'de> FromFlattened<'de> for Item<'de>

Source§

impl<'de> FromFlattened<'de> for Table<'de>