pub struct LoadSpec<'a> {Show 15 fields
pub key: &'a str,
pub sources: &'a [Source<'a>],
pub env_prefix: Option<&'a str>,
pub search: Option<Search<'a>>,
pub profile_env: Option<&'a str>,
pub defaults: Option<&'a Layer>,
pub remote: Option<&'a Remote>,
pub env_files: &'a [&'a str],
pub aliases: Option<&'a Aliases>,
pub env_bindings: Option<&'a EnvBindings>,
pub flags: Option<&'a Layer>,
pub overrides: Option<&'a Layer>,
pub nest: &'a str,
pub allow_empty_env: bool,
pub strict_env: bool,
}Expand description
Everything the loader needs: which layers, which section, which env prefix.
Prefer new and the with_* methods over a struct literal, so
that a later release can add a knob without breaking every call site.
Fields§
§key: &'a strThe configuration section this maps to, e.g. "db".
sources: &'a [Source<'a>]Layers, merged left to right. Later sources win.
env_prefix: Option<&'a str>Environment variable prefix, e.g. "APP_". Combined with key.
None ignores the environment entirely.
search: Option<Search<'a>>Where to look for configuration files by name, if anywhere.
Discovered files are merged before sources, so an
explicitly listed file still has the last word.
profile_env: Option<&'a str>Environment variable naming the active profile, e.g. "APP_ENV".
When it is set to production, every file gains a sibling layer:
config.toml is followed by config.production.toml, discovered or
listed alike. A variant that does not exist is skipped like any other
missing file.
defaults: Option<&'a Layer>Values below the files: consulted only when nothing else supplies a key.
remote: Option<&'a Remote>A document fetched from a remote store: above the files, below the environment.
env_files: &'a [&'a str].env files, read as the environment layer rather than as documents.
Merged in order, just below the real environment: a variable somebody exported for this run should beat a file in the repository.
aliases: Option<&'a Aliases>Old key paths that still resolve, filling a gap rather than overriding.
env_bindings: Option<&'a EnvBindings>Fields bound to environment variables by name: just above the prefixed environment layer, because a binding is the more specific statement.
flags: Option<&'a Layer>Values from the command line: above the environment, below overrides.
overrides: Option<&'a Layer>Values above everything, including the environment.
nest: &'a strSeparator that introduces nesting in an environment variable name.
Defaults to "__", so APP_DB_POOL__MAX_SIZE is pool.max_size. A
single separator cannot mean both “word break” and “nesting”, so
whatever this is set to, it has to be something a field name will not
contain.
allow_empty_env: boolWhether FOO= counts as set-to-empty.
Defaults to false, which treats it as unset. An unset value rendered
into a deployment template leaves exactly FOO=, and letting that blank
out a perfectly good configured value is a bad afternoon. Turn it on
when empty really is a value you need to be able to send.
strict_env: boolRejects environment values from the yes/no/on/off family instead of letting them arrive as strings where a boolean was meant.
Implementations§
Source§impl<'a> LoadSpec<'a>
impl<'a> LoadSpec<'a>
Sourcepub const fn new(key: &'a str, sources: &'a [Source<'a>]) -> Self
pub const fn new(key: &'a str, sources: &'a [Source<'a>]) -> Self
A spec that reads sources and selects key, ignoring the environment.
Sourcepub const fn with_search(self, name: &'a str, paths: &'a [&'a str]) -> Self
pub const fn with_search(self, name: &'a str, paths: &'a [&'a str]) -> Self
Looks for {name}.{ext} in each of paths, in order.
Every directory that has a match contributes one file, so the search
order is the layering order. Discovered files sit below the explicit
sources.
Sourcepub const fn with_profile_env(self, variable: &'a str) -> Self
pub const fn with_profile_env(self, variable: &'a str) -> Self
Layers a per-profile sibling over every file.
variable names the environment variable holding the profile, so the
profile itself is resolved at load time rather than baked in.
Sourcepub const fn with_defaults(self, layer: &'a Layer) -> Self
pub const fn with_defaults(self, layer: &'a Layer) -> Self
Values consulted only when no file and no variable supplies a key.
Sourcepub const fn with_env_files(self, files: &'a [&'a str]) -> Self
pub const fn with_env_files(self, files: &'a [&'a str]) -> Self
.env files, merged just below the real environment.
Needs the dotenv feature; without it, a non-empty list is an error at
load time naming the feature rather than a list silently ignored.
Sourcepub const fn with_aliases(self, aliases: &'a Aliases) -> Self
pub const fn with_aliases(self, aliases: &'a Aliases) -> Self
Old key paths that still resolve.
Sourcepub const fn with_env_bindings(self, bindings: &'a EnvBindings) -> Self
pub const fn with_env_bindings(self, bindings: &'a EnvBindings) -> Self
Fields bound to environment variables by name.
Sourcepub const fn with_remote(self, remote: &'a Remote) -> Self
pub const fn with_remote(self, remote: &'a Remote) -> Self
A remote store’s document, layered over the files.
Sourcepub const fn with_flags(self, layer: &'a Layer) -> Self
pub const fn with_flags(self, layer: &'a Layer) -> Self
Values from the command line, layered over the environment.
Sourcepub const fn with_overrides(self, layer: &'a Layer) -> Self
pub const fn with_overrides(self, layer: &'a Layer) -> Self
Values that win over the files, the environment and the flags alike.
Sourcepub const fn with_env(self, prefix: &'a str) -> Self
pub const fn with_env(self, prefix: &'a str) -> Self
Layers environment variables named {prefix}{KEY}_* over the files.
Sourcepub const fn with_nest(self, separator: &'a str) -> Self
pub const fn with_nest(self, separator: &'a str) -> Self
Uses separator instead of __ to introduce nesting.
Sourcepub const fn with_empty_env(self, allow: bool) -> Self
pub const fn with_empty_env(self, allow: bool) -> Self
Treats FOO= as set-to-empty rather than unset.
Sourcepub const fn with_strict_env(self, strict: bool) -> Self
pub const fn with_strict_env(self, strict: bool) -> Self
Rejects ambiguous environment spellings instead of guessing.
APP_DB_TLS=off reads like a boolean and arrives as the string
"off" — silently correct into a String field, silently wrong
everywhere else. Strict mode makes the yes/no/on/off family (and
null/nil/none) an error naming the variable; write true,
false, or the value you actually mean.
Trait Implementations§
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for LoadSpec<'a>
impl<'a> !UnwindSafe for LoadSpec<'a>
impl<'a> Freeze for LoadSpec<'a>
impl<'a> Send for LoadSpec<'a>
impl<'a> Sync for LoadSpec<'a>
impl<'a> Unpin for LoadSpec<'a>
impl<'a> UnsafeUnpin for LoadSpec<'a>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
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>
renamed to 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);