Struct figment::Profile[][src]

pub struct Profile(_);

A configuration profile: effectively a case-insensitive string.

See the top-level docs for details.

Implementations

impl Profile[src]

pub const Default: Profile[src]

The default profile: "default".

pub const Global: Profile[src]

The global profile: "global".

pub fn new(name: &str) -> Profile[src]

Constructs a profile with the name name.

Example

use figment::Profile;

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

pub const fn const_new(name: &'static str) -> Profile[src]

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

pub fn from_env(key: &str) -> Option<Self>[src]

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

pub fn from_env_or<P: Into<Profile>>(var: &str, default: P) -> Self[src]

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

pub fn as_str(&self) -> &UncasedStr[src]

Converts self into an &UncasedStr.

Example

use figment::Profile;

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

pub fn starts_with(&self, prefix: &str) -> bool[src]

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

pub fn is_custom(&self) -> bool[src]

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

pub fn collect(&self, dict: Dict) -> Map<Profile, Dict>[src]

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>

pub fn as_str(&self) -> &str[src]

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

pub fn len(&self) -> usize[src]

Returns the length, in bytes, of self.

Example

use uncased::UncasedStr;

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

pub fn starts_with(&self, string: &str) -> bool[src]

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

impl Clone for Profile[src]

impl Debug for Profile[src]

impl Default for Profile[src]

impl Deref for Profile[src]

type Target = UncasedStr

The resulting type after dereferencing.

impl<'de> Deserialize<'de> for Profile[src]

impl Display for Profile[src]

impl Eq for Profile[src]

impl From<Profile> for String[src]

impl<T: AsRef<str>> From<T> for Profile[src]

impl Hash for Profile[src]

impl Ord for Profile[src]

impl PartialEq<&'_ Profile> for Profile[src]

impl PartialEq<&'_ str> for Profile[src]

impl PartialEq<Profile> for Profile[src]

impl PartialEq<Profile> for &Profile[src]

impl PartialEq<str> for Profile[src]

impl PartialOrd<Profile> for Profile[src]

impl Serialize for Profile[src]

impl StructuralEq for Profile[src]

impl StructuralPartialEq for Profile[src]

Auto Trait Implementations

impl RefUnwindSafe for Profile

impl Send for Profile

impl Sync for Profile

impl Unpin for Profile

impl UnwindSafe for Profile

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: for<'de> Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,