pub struct Profile(_);
Expand description
A configuration profile: effectively a case-insensitive string.
See the top-level docs for details.
Implementations
sourceimpl Profile
impl Profile
sourcepub fn new(name: &str) -> Profile
pub fn new(name: &str) -> Profile
Constructs a profile with the name name
.
Example
use figment::Profile;
let profile = Profile::new("staging");
assert_eq!(profile, "staging");
assert_eq!(profile, "STAGING");
sourcepub const fn const_new(name: &'static str) -> Profile
pub const fn const_new(name: &'static str) -> Profile
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");
sourcepub fn from_env(key: &str) -> Option<Self>
pub fn from_env(key: &str) -> Option<Self>
Constructs a profile from the value of the environment variable with
name key
, if one is present. The search for key
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(())
});
sourcepub fn from_env_or<P: Into<Profile>>(var: &str, default: P) -> Self
pub fn from_env_or<P: Into<Profile>>(var: &str, default: P) -> Self
Constructs a profile from the value of the environment variable with
name var
, if one is present, or default
if one is not. The search
for var
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(())
});
sourcepub fn as_str(&self) -> &UncasedStr
pub fn as_str(&self) -> &UncasedStr
Converts self
into an &UncasedStr
.
Example
use figment::Profile;
let profile = Profile::new("static");
let string = profile.as_str();
sourcepub fn starts_with(&self, prefix: &str) -> bool
pub fn starts_with(&self, prefix: &str) -> bool
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"));
Methods from Deref<Target = UncasedStr>
sourcepub fn as_str(&self) -> &str
pub fn as_str(&self) -> &str
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!");
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the length, in bytes, of self
.
Example
use uncased::UncasedStr;
let uncased_str = UncasedStr::new("Hello!");
assert_eq!(uncased_str.len(), 6);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
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());
sourcepub fn starts_with(&self, string: &str) -> bool
pub fn starts_with(&self, string: &str) -> bool
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
sourceimpl Deref for Profile
impl Deref for Profile
type Target = UncasedStr
type Target = UncasedStr
The resulting type after dereferencing.
sourcefn deref(&self) -> &UncasedStr
fn deref(&self) -> &UncasedStr
Dereferences the value.
sourceimpl<'de> Deserialize<'de> for Profile
impl<'de> Deserialize<'de> for Profile
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 Ord for Profile
impl Ord for Profile
1.21.0 · sourcefn max(self, other: Self) -> Self
fn max(self, other: Self) -> Self
Compares and returns the maximum of two values. Read more
1.21.0 · sourcefn min(self, other: Self) -> Self
fn min(self, other: Self) -> Self
Compares and returns the minimum of two values. Read more
1.50.0 · sourcefn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
fn clamp(self, min: Self, max: Self) -> Selfwhere
Self: PartialOrd<Self>,
Restrict a value to a certain interval. Read more
sourceimpl PartialEq<&Profile> for Profile
impl PartialEq<&Profile> for Profile
sourceimpl PartialEq<&str> for Profile
impl PartialEq<&str> for Profile
sourceimpl PartialEq<Profile> for &Profile
impl PartialEq<Profile> for &Profile
sourceimpl PartialEq<Profile> for &str
impl PartialEq<Profile> for &str
sourceimpl PartialEq<Profile> for Profile
impl PartialEq<Profile> for Profile
sourceimpl PartialEq<Profile> for str
impl PartialEq<Profile> for str
sourceimpl PartialEq<str> for Profile
impl PartialEq<str> for Profile
sourceimpl PartialOrd<Profile> for Profile
impl PartialOrd<Profile> for Profile
sourcefn partial_cmp(&self, other: &Profile) -> Option<Ordering>
fn partial_cmp(&self, other: &Profile) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Eq for Profile
impl StructuralEq for Profile
impl StructuralPartialEq for Profile
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
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
sourceimpl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
impl<Q, K> Equivalent<K> for Qwhere
Q: Eq + ?Sized,
K: Borrow<Q> + ?Sized,
sourcefn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Compare self to key
and return true
if they are equal.