Struct figment::providers::YamlExtended
source · pub struct YamlExtended;
yaml
only.Expand description
A YAML Extended Format
Data
provider.
Static constructor methods on YamlExtended
return a
Data
value with a generic marker of YamlExtended
.
Thus, further use occurs via methods on Data
.
use figment::providers::{Format, YamlExtended};
// Source directly from a source string...
let provider = YamlExtended::string("source-string");
// Or read from a file on disk.
let provider = YamlExtended::file("path-to-file");
// Or configured as nested (via Data::nested()):
let provider = YamlExtended::file("path-to-file").nested();
See also YamlExtended::from_str
for parsing details.
Implementations§
source§impl YamlExtended
impl YamlExtended
sourcepub fn from_str<'de, T: DeserializeOwned>(s: &'de str) -> Result<T>
pub fn from_str<'de, T: DeserializeOwned>(s: &'de str) -> Result<T>
This “YAML Extended” format parser implements the draft “Merge Key
Language-Independent Type for YAML™ Version
1.1” spec via
serde_yaml::Value::apply_merge()
. This method is not intended to
be used directly but rather indirectly by making use of YamlExtended
as a provider. The extension is not part of any officially supported
YAML release and is deprecated entirely since YAML 1.2. Using
YamlExtended
instead of Yaml
enables merge keys, allowing YAML
like the following to parse with key merges applied:
tasks:
build: &webpack_shared
command: webpack
args: build
inputs:
- 'src/**/*'
start:
<<: *webpack_shared
args: start
§Example
use serde::Deserialize;
use figment::{Figment, Jail, providers::{Format, Yaml, YamlExtended}};
#[derive(Debug, PartialEq, Deserialize)]
struct Circle {
x: usize,
y: usize,
r: usize,
}
#[derive(Debug, PartialEq, Deserialize)]
struct Config {
circle1: Circle,
circle2: Circle,
circle3: Circle,
}
Jail::expect_with(|jail| {
jail.create_file("Config.yaml", r#"
point: &POINT { x: 1, y: 2 }
radius: &RADIUS
r: 10
circle1:
<<: *POINT
r: 3
circle2:
<<: [ *POINT, *RADIUS ]
circle3:
<<: [ *POINT, *RADIUS ]
y: 14
r: 20
"#)?;
let config: Config = Figment::from(YamlExtended::file("Config.yaml")).extract()?;
assert_eq!(config, Config {
circle1: Circle { x: 1, y: 2, r: 3 },
circle2: Circle { x: 1, y: 2, r: 10 },
circle3: Circle { x: 1, y: 14, r: 20 },
});
// Note that just `Yaml` would fail, since it doesn't support merge.
let config = Figment::from(Yaml::file("Config.yaml"));
assert!(config.extract::<Config>().is_err());
Ok(())
});
Trait Implementations§
source§impl Format for YamlExtended
impl Format for YamlExtended
source§const NAME: &'static str = "YAML Extended"
const NAME: &'static str = "YAML Extended"
"JSON"
or "TOML"
.source§fn from_str<'de, T: DeserializeOwned>(s: &'de str) -> Result<T, Error>
fn from_str<'de, T: DeserializeOwned>(s: &'de str) -> Result<T, Error>
string
as the data format Self
as a T
or returns an error
if the string
is an invalid T
. Note: This method is not
intended to be called directly. Instead, it is intended to be
implemented and then used indirectly via the Data::file()
or
Data::string()
methods.source§fn file<P: AsRef<Path>>(path: P) -> Data<Self>
fn file<P: AsRef<Path>>(path: P) -> Data<Self>
Data
provider that sources its values by parsing the file at
path
as format Self
. See Data::file()
for more details. The
default implementation calls Data::file(path)
.source§fn file_exact<P: AsRef<Path>>(path: P) -> Data<Self>
fn file_exact<P: AsRef<Path>>(path: P) -> Data<Self>
Data
provider that sources its values by parsing the file at
path
as format Self
. See Data::file_exact()
for more details. The
default implementation calls Data::file_exact(path)
.source§fn string(string: &str) -> Data<Self>
fn string(string: &str) -> Data<Self>
Data
provider that sources its values by parsing string
as
format Self
. See Data::string()
for more details. The default
implementation calls Data::string(string)
.source§fn from_path<T: DeserializeOwned>(path: &Path) -> Result<T, Self::Error>
fn from_path<T: DeserializeOwned>(path: &Path) -> Result<T, Self::Error>
path
as the data format Self
as a T
or returns
an error if the string
is an invalid T
. The default implementation
calls Format::from_str()
with the contents of the file. Note:
This method is not intended to be called directly. Instead, it is
intended to be implemented on special occasions and then used
indirectly via the Data::file()
or Data::string()
methods.Auto Trait Implementations§
impl Freeze for YamlExtended
impl RefUnwindSafe for YamlExtended
impl Send for YamlExtended
impl Sync for YamlExtended
impl Unpin for YamlExtended
impl UnwindSafe for YamlExtended
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> 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>
Returns self
with the
fg()
set to
Color::BrightBlack
.
§Example
println!("{}", value.bright_black());
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>
Returns self
with the
fg()
set to
Color::BrightGreen
.
§Example
println!("{}", value.bright_green());
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>
Returns self
with the
fg()
set to
Color::BrightWhite
.
§Example
println!("{}", value.bright_white());
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 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);