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

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));

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

Returns a copy of the value. Read more
Performs copy-assignment from source. Read more
Formats the value using the given formatter. Read more
The resulting type after dereferencing.
Dereferences the value.
Deserialize this value from the given Serde deserializer. Read more
Converts to this type from the input type.
This method tests for self and other values to be equal, and is used by ==. Read more
This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason. Read more
Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more
Converts to this type from the input type.

Returns the argument unchanged.

Calls U::from(self).

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

The resulting type after obtaining ownership.
Creates owned data from borrowed data, usually by cloning. Read more
Uses borrowed data to replace owned data, usually by cloning. Read more
The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.