Skip to main content

KeyedContainerBuilder

Enum KeyedContainerBuilder 

Source
pub enum KeyedContainerBuilder<Container, Target> {
    Unspecified,
    Some(Container),
    _PhantomData(PhantomData<fn() -> Target>),
}
Expand description

Builder type for keyed containers, such as HashMap (as opposed to unkeyed containers like Vec). This is not required to be used, but is a convient shortcut for map types’ implementations.

Types using this as their builder must implement KeyedContainer.

For unkeyed containers, see UnkeyedContainerBuilder.

Example usage:

use std::fmt::Display;

use confik::{
    helpers::{BuilderOf, KeyedContainer, KeyedContainerBuilder},
    Configuration,
};
use serde::Deserialize;

struct MyMap<K, V> {
    // ...
}

impl<'de, K, V> Deserialize<'de> for MyMap<K, V> {
    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
    where
        D: serde::Deserializer<'de>,
    {
        // ...
    }
}

impl<K, V> Default for MyMap<K, V> {
    fn default() -> Self {
        // ...
    }
}

impl<K, V> IntoIterator for MyMap<K, V> {
    type Item = (K, V);

    type IntoIter = // ...

    fn into_iter(self) -> Self::IntoIter {
        // ...
    }
}

impl<'a, K, V> IntoIterator for &'a MyMap<K, V> {
    type Item = (&'a K, &'a V);

    type IntoIter = // ...

    fn into_iter(self) -> Self::IntoIter {
        // ...
    }
}

impl<K, V> FromIterator<(K, V)> for MyMap<K, V> {
    fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self {
        // ...
    }
}

impl<K, V> KeyedContainer for MyMap<K, V> {
    type Key = K;

    type Value = V;

    fn insert(&mut self, k: Self::Key, v: Self::Value) {
        // ...
    }

    fn remove(&mut self, k: &Self::Key) -> Option<Self::Value> {
        // ...
    }
}

impl<K, V> Configuration for MyMap<K, V>
where
    K: Display + 'static,
    V: Configuration,
    BuilderOf<V>: 'static,
{
    type Builder = KeyedContainerBuilder<MyMap<K, BuilderOf<V>>, Self>;
}

Variants§

§

Unspecified

No data has been provided yet.

Default to None but allow overwriting by later merges.

§

Some(Container)

Data has been provided.

Will not be overwritten by later merges.

§

_PhantomData(PhantomData<fn() -> Target>)

Never instantiated, used to hold the Target type.

Trait Implementations§

Source§

impl<Container, Target> ConfigurationBuilder for KeyedContainerBuilder<Container, Target>
where Self: DeserializeOwned, Container: KeyedContainer + IntoIterator<Item = (KeyOf<Container>, ValueOf<Container>)> + 'static, KeyOf<Container>: Display, ValueOf<Container>: ConfigurationBuilder + 'static, Target: Default + FromIterator<(KeyOf<Container>, TargetOf<ValueOf<Container>>)>, for<'a> &'a Container: IntoIterator<Item = (&'a KeyOf<Container>, &'a ValueOf<Container>)>,

Source§

type Target = Target

The target that will be converted into. See Configuration.
Source§

fn merge(self, other: Self) -> Self

Combines two builders recursively, preferring self’s data, if present.
Source§

fn try_build(self) -> Result<Self::Target, Error>

This will probably delegate to TryInto but allows it to be implemented for types foreign to the library.
Source§

fn contains_non_secret_data(&self) -> Result<bool, UnexpectedSecret>

Called recursively on each field, aiming to hit all SecretBuilders. This is only called when Source::allows_secrets is false. Read more
Source§

impl<Container: Debug, Target: Debug> Debug for KeyedContainerBuilder<Container, Target>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<Container, Target> Default for KeyedContainerBuilder<Container, Target>

Source§

fn default() -> KeyedContainerBuilder<Container, Target>

Returns the “default value” for a type. Read more
Source§

impl<'de, Container, Target> Deserialize<'de> for KeyedContainerBuilder<Container, Target>
where Container: Deserialize<'de>,

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl<Container, Target> From<Container> for KeyedContainerBuilder<Container, Target>

Source§

fn from(value: Container) -> Self

Converts to this type from the input type.
Source§

impl<Container: Hash, Target: Hash> Hash for KeyedContainerBuilder<Container, Target>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<Container: Ord, Target: Ord> Ord for KeyedContainerBuilder<Container, Target>

Source§

fn cmp(&self, other: &KeyedContainerBuilder<Container, Target>) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl<Container: PartialEq, Target: PartialEq> PartialEq for KeyedContainerBuilder<Container, Target>

Source§

fn eq(&self, other: &KeyedContainerBuilder<Container, Target>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl<Container: PartialOrd, Target: PartialOrd> PartialOrd for KeyedContainerBuilder<Container, Target>

Source§

fn partial_cmp( &self, other: &KeyedContainerBuilder<Container, Target>, ) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl<Container: Eq, Target: Eq> Eq for KeyedContainerBuilder<Container, Target>

Source§

impl<Container, Target> StructuralPartialEq for KeyedContainerBuilder<Container, Target>

Auto Trait Implementations§

§

impl<Container, Target> Freeze for KeyedContainerBuilder<Container, Target>
where Container: Freeze,

§

impl<Container, Target> RefUnwindSafe for KeyedContainerBuilder<Container, Target>
where Container: RefUnwindSafe,

§

impl<Container, Target> Send for KeyedContainerBuilder<Container, Target>
where Container: Send,

§

impl<Container, Target> Sync for KeyedContainerBuilder<Container, Target>
where Container: Sync,

§

impl<Container, Target> Unpin for KeyedContainerBuilder<Container, Target>
where Container: Unpin,

§

impl<Container, Target> UnsafeUnpin for KeyedContainerBuilder<Container, Target>
where Container: UnsafeUnpin,

§

impl<Container, Target> UnwindSafe for KeyedContainerBuilder<Container, Target>
where Container: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<!> for T

Source§

fn from(t: !) -> T

Converts to this type from the input type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,