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>)>,
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
type Target = Target
The target that will be converted into. See
Configuration.Source§fn merge(self, other: Self) -> Self
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>
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>
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 moreSource§impl<Container, Target> Default for KeyedContainerBuilder<Container, Target>
impl<Container, Target> Default for KeyedContainerBuilder<Container, Target>
Source§fn default() -> KeyedContainerBuilder<Container, Target>
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>,
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>,
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>
impl<Container, Target> From<Container> for KeyedContainerBuilder<Container, Target>
Source§impl<Container: Ord, Target: Ord> Ord for KeyedContainerBuilder<Container, Target>
impl<Container: Ord, Target: Ord> Ord for KeyedContainerBuilder<Container, Target>
Source§fn cmp(&self, other: &KeyedContainerBuilder<Container, Target>) -> Ordering
fn cmp(&self, other: &KeyedContainerBuilder<Container, Target>) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl<Container: PartialEq, Target: PartialEq> PartialEq for KeyedContainerBuilder<Container, Target>
impl<Container: PartialEq, Target: PartialEq> PartialEq for KeyedContainerBuilder<Container, Target>
Source§fn eq(&self, other: &KeyedContainerBuilder<Container, Target>) -> bool
fn eq(&self, other: &KeyedContainerBuilder<Container, Target>) -> bool
Tests for
self and other values to be equal, and is used by ==.Source§impl<Container: PartialOrd, Target: PartialOrd> PartialOrd for KeyedContainerBuilder<Container, Target>
impl<Container: PartialOrd, Target: PartialOrd> PartialOrd for KeyedContainerBuilder<Container, Target>
impl<Container: Eq, Target: Eq> Eq for KeyedContainerBuilder<Container, Target>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more