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::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::Arrays are never appended but always replaced
(CONFIG_FILE_MERGE_PEPTH=2).
Append key, value pairs from other to self.
use tpnote_lib::config::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::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>,
Deserialize this value from the given Serde deserializer. Read more
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
Mutably borrows from an owned value. Read more
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>
Converts
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>
Converts
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