pub struct Layer { /* private fields */ }Expand description
A set of values addressed by dotted path.
Layer::new() is const, so this lives in a static — which is how
#[dynamic_config] emits it. Every method takes &self, so a layer can be
written to from anywhere without threading a handle around.
§Example
use dynamic_config::Layer;
static OVERRIDES: Layer = Layer::new();
assert!(OVERRIDES.is_empty());
OVERRIDES.set("pool.max_size", 32u16).unwrap();
assert!(!OVERRIDES.is_empty());
OVERRIDES.clear();Implementations§
Source§impl Layer
impl Layer
Sourcepub fn set<T: Serialize>(&self, path: &str, value: T) -> Result<(), Error>
pub fn set<T: Serialize>(&self, path: &str, value: T) -> Result<(), Error>
Sets path — dotted for nested fields, as in "pool.max_size".
Setting the same path again replaces it. The value is converted once, here, so a type that cannot be represented fails at the call site rather than at the next reload.
§Errors
If path is empty or has a blank segment, or if value cannot be
serialized.
Sourcepub fn set_text(&self, path: &str, text: &str) -> Result<(), Error>
pub fn set_text(&self, path: &str, text: &str) -> Result<(), Error>
Sets path from text, read the way an environment variable is.
"8080" becomes a number, "true" a boolean, "[a, b]" a list — the
same loose reading the environment layer gets, so a value means the same
thing whether it arrives as APP_DB_PORT=8080 or --set db.port=8080.
§Errors
If path is empty or has a blank segment.
Sourcepub fn set_assignments<I, S>(&self, assignments: I) -> Result<(), Error>
pub fn set_assignments<I, S>(&self, assignments: I) -> Result<(), Error>
Sets every key=value in assignments.
The shape behind a --set key=value flag. A pair with no = is an
error naming the offending argument rather than a silently ignored one.
§Errors
If an assignment has no =, or its key is not a usable path.
Sourcepub fn bind_clap(
&self,
matches: &ArgMatches,
bindings: &[(&str, &str)],
) -> Result<(), Error>
Available on crate feature clap only.
pub fn bind_clap( &self, matches: &ArgMatches, bindings: &[(&str, &str)], ) -> Result<(), Error>
clap only.Copies clap arguments into this layer, by (argument id, key path).
Only arguments that came from the command line are taken. clap’s own
default_value looks identical to a typed flag in ArgMatches, and
letting a clap default outrank a configuration file would invert the
whole precedence order — the file would be ignored in favour of a
fallback nobody asked for.
Values are read the way environment variables are, so --port 8080 and
APP_DB_PORT=8080 mean the same thing whatever type the argument was
declared with.
flags.bind_clap(matches, &[("db-host", "host"), ("db-port", "port")])?;§Errors
If a key path is unusable, or an argument’s value is not valid UTF-8.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for Layer
impl RefUnwindSafe for Layer
impl Send for Layer
impl Sync for Layer
impl Unpin for Layer
impl UnsafeUnpin for Layer
impl UnwindSafe for Layer
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> 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);