Struct figment::Profile[][src]

pub struct Profile(_);
Expand description

A configuration profile: effectively a case-insensitive string.

See the top-level docs for details.

Implementations

The default profile: "default".

The global profile: "global".

Constructs a profile with the name name.

Example

use figment::Profile;

let profile = Profile::new("staging");
assert_eq!(profile, "staging");
assert_eq!(profile, "STAGING");

A const to construct a profile with the name name.

Example

use figment::Profile;

const STAGING: Profile = Profile::const_new("staging");

assert_eq!(STAGING, "staging");
assert_eq!(STAGING, "STAGING");

Constructs a profile from the value of the environment variable with name name, if one is present. The search for name is case-insensitive.

Example

use figment::{Profile, Jail};

Jail::expect_with(|jail| {
    jail.set_env("MY_PROFILE", "secret");

    assert_eq!(Profile::from_env("MY_PROFILE"), Some("secret".into()));
    assert_eq!(Profile::from_env("MY_PROFILE"), Some("secret".into()));
    assert_eq!(Profile::from_env("MY_profile"), Some("secret".into()));
    assert_eq!(Profile::from_env("other_profile"), None);
    Ok(())
});

Constructs a profile from the value of the environment variable with name name, if one is present, or default if one is not. The search for name is case-insensitive.

Example

use figment::{Profile, Jail};

Jail::expect_with(|jail| {
    jail.set_env("MY_PROFILE", "secret");

    assert_eq!(Profile::from_env_or("MY_PROFILE", "default"), "secret");
    assert_eq!(Profile::from_env_or("MY_profile", "default"), "secret");
    assert_eq!(Profile::from_env_or("other_prof", "default"), "default");
    Ok(())
});

Converts self into an &UncasedStr.

Example

use figment::Profile;

let profile = Profile::new("static");
let string = profile.as_str();

Returns true iff self case-insensitively starts with prefix.

Example

use figment::Profile;

let profile = Profile::new("static");
assert!(profile.starts_with("STAT"));
assert!(profile.starts_with("stat"));
assert!(profile.starts_with("static"));

Returns true iff self is neither “default” nor “global”.

Example

use figment::Profile;

let profile = Profile::new("static");
assert!(profile.is_custom());

assert!(!Profile::Default.is_custom());
assert!(!Profile::Global.is_custom());

Creates a new map with a single key of *self and a value of dict.

Example

use figment::{Profile, util::map};

let profile = Profile::new("static");
let map = profile.collect(map!["hi".into() => 123.into()]);

Methods from Deref<Target = UncasedStr>

Returns self as an &str.

Example

use uncased::UncasedStr;

let uncased_str = UncasedStr::new("Hello!");
assert_eq!(uncased_str.as_str(), "Hello!");
assert_ne!(uncased_str.as_str(), "hELLo!");

Returns the length, in bytes, of self.

Example

use uncased::UncasedStr;

let uncased_str = UncasedStr::new("Hello!");
assert_eq!(uncased_str.len(), 6);

Returns true if self has a length of zero bytes.

Examples

use uncased::UncasedStr;

let s = UncasedStr::new("");
assert!(s.is_empty());

let s = UncasedStr::new("not empty");
assert!(!s.is_empty());

Returns true if self starts with any casing of the string string; otherwise, returns false.

Example

use uncased::UncasedStr;

let uncased_str = UncasedStr::new("MoOO");
assert!(uncased_str.starts_with("moo"));
assert!(uncased_str.starts_with("MOO"));
assert!(uncased_str.starts_with("MOOO"));
assert!(!uncased_str.starts_with("boo"));

let uncased_str = UncasedStr::new("Bèe");
assert!(!uncased_str.starts_with("Be"));
assert!(uncased_str.starts_with("Bè"));
assert!(uncased_str.starts_with("Bè"));
assert!(uncased_str.starts_with("bèe"));
assert!(uncased_str.starts_with("BèE"));

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

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

The resulting type after dereferencing.

Dereferences the value.

Deserialize this value from the given Serde deserializer. Read more

Formats the value using the given formatter. Read more

Performs the conversion.

Performs the conversion.

Feeds this value into the given Hasher. Read more

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

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests less than (for self and other) and is used by the < operator. Read more

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more

This method tests greater than (for self and other) and is used by the > operator. Read more

This method tests greater than or equal to (for self and other) and is used by the >= operator. 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

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. 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.