pub struct Profile(/* private fields */);
Expand description
A configuration profile: effectively a case-insensitive string.
See the top-level docs for details.
Implementations§
source§impl 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§
source§impl Deref for Profile
impl Deref for Profile
§type Target = UncasedStr
type Target = UncasedStr
source§fn deref(&self) -> &UncasedStr
fn deref(&self) -> &UncasedStr
source§impl<'de> Deserialize<'de> for Profile
impl<'de> Deserialize<'de> for Profile
source§fn 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>,
source§impl Ord for Profile
impl Ord for Profile
source§impl PartialEq<&Profile> for Profile
impl PartialEq<&Profile> for Profile
source§impl PartialEq<&str> for Profile
impl PartialEq<&str> for Profile
source§impl PartialEq<Profile> for &Profile
impl PartialEq<Profile> for &Profile
source§impl PartialEq<Profile> for &str
impl PartialEq<Profile> for &str
source§impl PartialEq<Profile> for Profile
impl PartialEq<Profile> for Profile
source§impl PartialEq<Profile> for str
impl PartialEq<Profile> for str
source§impl PartialOrd<Profile> for Profile
impl PartialOrd<Profile> for Profile
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl 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§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<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,
source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key
and return true
if they are equal.source§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere T: ?Sized,
source§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the foreground set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red()
and
green()
, which have the same functionality but are
pithier.
Example
Set foreground color to white using fg()
:
use yansi::{Paint, Color};
painted.fg(Color::White);
Set foreground color to white using white()
.
use yansi::Paint;
painted.white();
source§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
source§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
source§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
source§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightYellow
.
Example
println!("{}", value.bright_yellow());
source§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
source§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
Returns self
with the
fg()
set to
Color::BrightMagenta
.
Example
println!("{}", value.bright_magenta());
source§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
source§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
source§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self
with the background set to
value
.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red()
and
on_green()
, which have the same functionality but
are pithier.
Example
Set background color to red using fg()
:
use yansi::{Paint, Color};
painted.bg(Color::Red);
Set background color to red using on_red()
.
use yansi::Paint;
painted.on_red();
source§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
source§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
source§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlack
.
Example
println!("{}", value.on_bright_black());
source§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
source§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightGreen
.
Example
println!("{}", value.on_bright_green());
source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightYellow
.
Example
println!("{}", value.on_bright_yellow());
source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightBlue
.
Example
println!("{}", value.on_bright_blue());
source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightMagenta
.
Example
println!("{}", value.on_bright_magenta());
source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightCyan
.
Example
println!("{}", value.on_bright_cyan());
source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
Returns self
with the
bg()
set to
Color::BrightWhite
.
Example
println!("{}", value.on_bright_white());
source§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling Attribute
value
.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold()
and
underline()
, which have the same functionality
but are pithier.
Example
Make text bold using attr()
:
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);
Make text bold using using bold()
.
use yansi::Paint;
painted.bold();
source§fn underline(&self) -> Painted<&T>
fn underline(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::Underline
.
Example
println!("{}", value.underline());
source§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
Returns self
with the
attr()
set to
Attribute::RapidBlink
.
Example
println!("{}", value.rapid_blink());
source§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi
Quirk
value
.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask()
and
wrap()
, which have the same functionality but are
pithier.
Example
Enable wrapping using .quirk()
:
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);
Enable wrapping using wrap()
.
use yansi::Paint;
painted.wrap();
source§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the Condition
value
applies. Replaces any previous condition.
See the crate level docs for more details.
Example
Enable styling painted
only when both stdout
and stderr
are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);