pub struct CfgVal(/* private fields */);
Expand description
A newtype holding configuration data.
Implementations§
Source§impl CfgVal
This API deals with configuration values.
impl CfgVal
This API deals with configuration values.
Sourcepub fn extend(&mut self, other: Self)
pub fn extend(&mut self, other: Self)
Append key, value pairs from other to self
.
use tpnote_lib::config_value::CfgVal;
use std::str::FromStr;
let toml1 = "\
[arg_default]
scheme = 'zettel'
";
let toml2 = "\
[base_scheme]
name = 'some name'
";
let mut cfg1 = CfgVal::from_str(toml1).unwrap();
let cfg2 = CfgVal::from_str(toml2).unwrap();
let expected = CfgVal::from_str("\
[arg_default]
scheme = 'zettel'
[base_scheme]
name = 'some name'
").unwrap();
// Run test
cfg1.extend(cfg2);
assert_eq!(cfg1, expected);
pub fn insert(&mut self, key: String, val: Value)
Sourcepub fn merge(self, other: Self) -> Self
pub fn merge(self, other: Self) -> Self
Merges configuration values from other
into self
and returns the result. The top level element is a set of key and value
pairs (map). If one of its values is a Value::Array
, then the
corresponding array from other
is appended.
Otherwise the corresponding other
value replaces the self
value.
Deeper nested Value::Array
s are never appended but always replaced
(CONFIG_FILE_MERGE_PEPTH=2
).
Append key, value pairs from other to self
.
use tpnote_lib::config_value::CfgVal;
use std::str::FromStr;
let toml1 = "\
version = '1.0.0'
[[scheme]]
name = 'default'
";
let toml2 = "\
version = '2.0.0'
[[scheme]]
name = 'zettel'
";
let mut cfg1 = CfgVal::from_str(toml1).unwrap();
let cfg2 = CfgVal::from_str(toml2).unwrap();
let expected = CfgVal::from_str("\
version = '2.0.0'
[[scheme]]
name = 'default'
[[scheme]]
name = 'zettel'
").unwrap();
// Run test
let res = cfg1.merge(cfg2);
assert_eq!(res, expected);
Sourcepub fn to_value(self) -> Value
pub fn to_value(self) -> Value
Convert to toml::Value
.
use tpnote_lib::config_value::CfgVal;
use std::str::FromStr;
let toml1 = "\
version = 1
[[scheme]]
name = 'default'
";
let cfg1 = CfgVal::from_str(toml1).unwrap();
let expected: toml::Value = toml::from_str(toml1).unwrap();
// Run test
let res = cfg1.to_value();
assert_eq!(res, expected);
Trait Implementations§
Source§impl<'de> Deserialize<'de> for CfgVal
impl<'de> Deserialize<'de> for CfgVal
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 TryFrom<CfgVal> for LibCfg
This constructor accepts as input the newtype CfgVal
containing
a toml::map::Map<String, Value>
. Each String
is the name of a top
level configuration variable.
The inner Map is expected to be a data structure that can be copied into
the internal temporary variable LibCfgRaw
. This internal variable
is then processed and the result is stored in a LibCfg
struct. For details
see the impl TryFrom<LibCfgRaw> for LibCfg
. The processing occurs as
follows:
impl TryFrom<CfgVal> for LibCfg
This constructor accepts as input the newtype CfgVal
containing
a toml::map::Map<String, Value>
. Each String
is the name of a top
level configuration variable.
The inner Map is expected to be a data structure that can be copied into
the internal temporary variable LibCfgRaw
. This internal variable
is then processed and the result is stored in a LibCfg
struct. For details
see the impl TryFrom<LibCfgRaw> for LibCfg
. The processing occurs as
follows:
- Merge each incomplete
CfgVal(key="scheme")
intoCfgVal(key="base_scheme")
and store the resultingscheme
struct inLibCfg.scheme
. - If
CfgVal(key="html_tmpl.viewer_highlighting_css")
is empty, generate the value fromCfgVal(key="tmpl.viewer_highlighting_theme")
. - Do the same for
CfgVal(key="html_tmpl.exporter_highlighting_css")
.
impl StructuralPartialEq for CfgVal
Auto Trait Implementations§
impl Freeze for CfgVal
impl RefUnwindSafe for CfgVal
impl Send for CfgVal
impl Sync for CfgVal
impl Unpin for CfgVal
impl UnwindSafe for CfgVal
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more