pub struct FileEnv { /* private fields */ }Expand description
Provider that reads config values from the environment or from files pointed to by the environment.
The config value foo will be read either from the env variable FOO or from the file
pointed to by FOO_FILE.
#[derive(Deserialize)]
struct Config {
foo: String,
bar: String,
}
// ENV:
// - `APP_FOO=foo_value`
// - `APP_BAR_FILE=./secret_file`
//
// Contents of the file `./secret_file`: `bar_value`
let config: Config = Figment::new()
.merge(FileEnv::from_env(Env::prefixed("APP_")))
.extract()?;
assert_eq!(config.foo, "foo_value");
assert_eq!(config.bar, "bar_value");Implementations§
Source§impl FileEnv
impl FileEnv
Sourcepub fn from_env(env: Env) -> Self
pub fn from_env(env: Env) -> Self
Build from a figment::providers::Env. Any restriction or transformation applied
to the env will propagate to the resulting FileEnv.
In particular, it is recommended to use figment::providers::Env::prefixed.
Note that figment::providers::Env::only and figment::providers::Env::ignore
should not be used. Use FileEnv::only and FileEnv::ignore instead.
use figment::providers::Env;
use figment_file_env_provider::FileEnv;
let file_env = FileEnv::from_env(Env::prefixed("MY_APP_"));Sourcepub fn with_suffix(self, suffix: &str) -> Self
pub fn with_suffix(self, suffix: &str) -> Self
Change the suffix used to detect env variables that point to files (“_FILE” by default).
// ENV: `APP_FOO_PATH=./secret_file`
// Contents of `./secret_file`: `32`
let config: Config = Figment::new()
.merge(FileEnv::from_env(Env::prefixed("APP_")).with_suffix("_PATH"))
.extract()?;
assert_eq!(config.foo, 32);Note that the suffix cannot be changed after calling FileEnv::only or
FileEnv::ignore.
Sourcepub fn only(self, keys: &[&str]) -> FileEnvWithRestrictions
pub fn only(self, keys: &[&str]) -> FileEnvWithRestrictions
Restrict the provider to process only the given list of keys (and their “_FILE” counterparts).
IMPORTANT: This should be used instead of figment::providers::Env::only otherwise
the “_FILE” variants won’t be supported.
use figment::providers::Env;
use figment_file_env_provider::FileEnv;
// This provider will look at the variables FOO, FOO_FILE, BAR and BAR_FILE.
let file_env = FileEnv::from_env(Env::prefixed("MY_APP_")).only(&["foo", "bar"]);Sourcepub fn ignore(self, keys: &[&str]) -> FileEnvWithRestrictions
pub fn ignore(self, keys: &[&str]) -> FileEnvWithRestrictions
Restrict the provider to ignore the given list of keys (and their “_FILE” counterparts).
IMPORTANT: This should be used instead of figment::providers::Env::ignore otherwise
the “_FILE” variants won’t be ignored.
use figment::providers::Env;
use figment_file_env_provider::FileEnv;
// This provider will not look at the variables FOO, FOO_FILE, BAR and BAR_FILE.
let file_env = FileEnv::from_env(Env::prefixed("MY_APP_")).ignore(&["foo", "bar"]);Trait Implementations§
Auto Trait Implementations§
impl Freeze for FileEnv
impl !RefUnwindSafe for FileEnv
impl !Send for FileEnv
impl !Sync for FileEnv
impl Unpin for FileEnv
impl !UnwindSafe for FileEnv
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
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>
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>
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>
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>
Source§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
Source§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
Source§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
Source§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
Source§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
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 rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
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 clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.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);