[−][src]Struct figment::providers::Serialized
A Provider
that sources values directly from a serialize type.
Provider Details
-
Profile
This provider does not set a profile.
-
Metadata
This provider is named
T
(viastd::any::type_name
). The source location is set to the call site of the constructor. -
Data (Unkeyed)
When data is not keyed,
T
is expected to serialize to aDict
and is emitted directly as the value for the configured profile. -
Data (Keyed)
When keyed, the
T
can serialize as anyValue
and is emitted as the value of the configuredkey
. Specifically, nested dictionaries are created for every path component delimited by.
in the key string (3 ina.b.c
), each dictionary mapping to its parent, and the value mapping to the leaf.
Fields
value: T
The value to be serialized and used as the provided data.
key: Option<String>
The key path (a.b.c
) to emit the value to or the root if None
.
profile: Profile
The profile to emit the value to. Defaults to Profile::Default
.
Implementations
impl<T> Serialized<T>
[src]
pub fn from<P: Into<Profile>>(value: T, profile: P) -> Serialized<T>
[src]
Constructs an (unkeyed) provider that emits value
to the profile
.
use serde::Deserialize; use figment::{Figment, Jail, providers::Serialized, util::map}; #[derive(Debug, PartialEq, Deserialize)] struct Config { numbers: Vec<usize>, } Jail::expect_with(|jail| { let map = map!["numbers" => &[1, 2, 3]]; // This is also `Serialized::defaults(&map)`; let figment = Figment::from(Serialized::from(&map, "default")); let config: Config = figment.extract()?; assert_eq!(config, Config { numbers: vec![1, 2, 3] }); // This is also `Serialized::defaults(&map).profile("debug")`; let figment = Figment::from(Serialized::from(&map, "debug")); let config: Config = figment.select("debug").extract()?; assert_eq!(config, Config { numbers: vec![1, 2, 3] }); Ok(()) });
pub fn defaults(value: T) -> Serialized<T>
[src]
Emits value
, which must serialize to a Dict
, to the Default
profile.
Equivalent to Serialized::from(value, Profile::Default)
.
See Serialized::from()
.
pub fn globals(value: T) -> Serialized<T>
[src]
Emits value
, which must serialize to a Dict
, to the Global
profile.
Equivalent to Serialized::from(value, Profile::Global)
.
See Serialized::from()
.
pub fn default(key: &str, value: T) -> Serialized<T>
[src]
Emits a nested dictionary to the Default
profile keyed by key
with
the final key mapping to value
.
Equivalent for Serialized::from(value, Profile::Default).key(key)
.
See Serialized::from()
and Serialized::key()
.
pub fn global(key: &str, value: T) -> Serialized<T>
[src]
Emits a nested dictionary to the Global
profile keyed by key
with
the final key mapping to value
.
Equivalent to Serialized::from(value, Profile::Global).key(key)
.
See Serialized::from()
and Serialized::key()
.
pub fn profile<P: Into<Profile>>(self, profile: P) -> Self
[src]
pub fn key(self, key: &str) -> Self
[src]
Trait Implementations
impl<T: Clone> Clone for Serialized<T>
[src]
fn clone(&self) -> Serialized<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T: Debug> Debug for Serialized<T>
[src]
impl<T: Serialize> Provider for Serialized<T>
[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Serialized<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Serialized<T> where
T: Send,
T: Send,
impl<T> Sync for Serialized<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Serialized<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Serialized<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,