pub struct Tagged<T> { /* private fields */ }
Expand description
A wrapper around any value of type T
and its Tag
.
use figment::{Figment, value::magic::Tagged, Jail};
use figment::providers::{Format, Toml};
#[derive(Debug, PartialEq, serde::Deserialize)]
struct Config {
number: Tagged<usize>,
}
Jail::expect_with(|jail| {
jail.create_file("Config.toml", r#"number = 10"#)?;
let figment = Figment::from(Toml::file("Config.toml"));
let c: Config = figment.extract()?;
assert_eq!(*c.number, 10);
let tag = c.number.tag();
let metadata = figment.get_metadata(tag).expect("number has tag");
assert!(!tag.is_default());
assert_eq!(metadata.name, "TOML file");
Ok(())
});
Implementations
sourceimpl<T> Tagged<T>
impl<T> Tagged<T>
sourcepub fn tag(&self) -> Tag
pub fn tag(&self) -> Tag
Returns the tag of the inner value if it is known. As long self
is a
leaf and was extracted from a Figment
, the returned
value is expected to be Some
.
Example
use figment::{Figment, Profile, value::magic::Tagged};
let figment = Figment::from(("key", "value"));
let tagged = figment.extract_inner::<Tagged<String>>("key").unwrap();
assert!(!tagged.tag().is_default());
assert_eq!(tagged.tag().profile(), Some(Profile::Global));
sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consumes self
and returns the inner value.
Example
use figment::{Figment, value::magic::Tagged};
let tagged = Figment::from(("key", "value"))
.extract_inner::<Tagged<String>>("key")
.unwrap();
let value = tagged.into_inner();
assert_eq!(value, "value");
Trait Implementations
sourceimpl<'de, T> Deserialize<'de> for Tagged<T>where
T: Deserialize<'de>,
impl<'de, T> Deserialize<'de> for Tagged<T>where
T: Deserialize<'de>,
sourcefn 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
sourceimpl<T: PartialEq> PartialEq<Tagged<T>> for Tagged<T>
impl<T: PartialEq> PartialEq<Tagged<T>> for Tagged<T>
impl<T: for<'de> Deserialize<'de>> Magic for Tagged<T>
Auto Trait Implementations
impl<T> RefUnwindSafe for Tagged<T>where
T: RefUnwindSafe,
impl<T> Send for Tagged<T>where
T: Send,
impl<T> Sync for Tagged<T>where
T: Sync,
impl<T> Unpin for Tagged<T>where
T: Unpin,
impl<T> UnwindSafe for Tagged<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more