pub struct YamlHash { /* private fields */ }Expand description
Improved YAML Hash
Implementations§
Source§impl YamlHash
impl YamlHash
Sourcepub fn merge(&self, other: &YamlHash) -> YamlHash
pub fn merge(&self, other: &YamlHash) -> YamlHash
Merge this YamlHash with another YamlHash to create a new YamlHash
use yaml_hash::YamlHash;
let hash = YamlHash::from("\
fruit:
apple: 1
banana: 2\
");
let other = YamlHash::from("\
fruit:
cherry:
sweet: 1
tart: 2\
");
assert_eq!(
hash.merge(&other).to_string(),
"\
fruit:
apple: 1
banana: 2
cherry:
sweet: 1
tart: 2\
",
);Sourcepub fn merge_str(&self, s: &str) -> Result<YamlHash>
pub fn merge_str(&self, s: &str) -> Result<YamlHash>
Merge this YamlHash with a YAML hash &str to create a new YamlHash
use yaml_hash::YamlHash;
let hash = YamlHash::from("\
fruit:
apple: 1
banana: 2\
");
let hash = hash.merge_str("\
fruit:
cherry:
sweet: 1
tart: 2\
").unwrap();
assert_eq!(
hash.to_string(),
"\
fruit:
apple: 1
banana: 2
cherry:
sweet: 1
tart: 2\
",
);§Errors
Returns an error if the YAML string is not a hash
Sourcepub fn merge_file<P: AsRef<Path>>(&self, path: P) -> Result<YamlHash>
pub fn merge_file<P: AsRef<Path>>(&self, path: P) -> Result<YamlHash>
Merge this YamlHash with a YAML hash file to create a new YamlHash
use yaml_hash::YamlHash;
let hash = YamlHash::from("\
fruit:
apple: 1
banana: 2\
");
let hash = hash.merge_file("tests/b.yaml").unwrap();
assert_eq!(
hash.to_string(),
"\
fruit:
apple: 1
banana: 2
cherry: 3\
",
);§Errors
Returns an error if not able to read the file at the given path to a string
Sourcepub fn get_yaml(&self, key: &str) -> Result<Yaml>
pub fn get_yaml(&self, key: &str) -> Result<Yaml>
Get the value for a dotted key as a Yaml
use yaml_hash::{Yaml, YamlHash};
let hash = YamlHash::from("\
fruit:
apple: 1
banana: 2
cherry:
sweet: 1
tart: 2\
");
assert_eq!(
hash.get_yaml("fruit.cherry.tart").unwrap(),
Yaml::Integer(2),
);§Errors
Returns an error if the given key is not valid or the value is not a hash
Sourcepub fn get(&self, key: &str) -> Result<YamlHash>
pub fn get(&self, key: &str) -> Result<YamlHash>
Get a value for a dotted key as a YamlHash
use yaml_hash::YamlHash;
let hash = YamlHash::from("\
fruit:
apple: 1
banana: 2
cherry:
sweet: 1
tart: 2\
");
assert_eq!(
hash.get("fruit.cherry").unwrap(),
YamlHash::from("\
sweet: 1
tart: 2\
"),
);§Errors
Returns an error if the given key is not valid or the value is not a hash
Trait Implementations§
impl Eq for YamlHash
impl StructuralPartialEq for YamlHash
Auto Trait Implementations§
impl Freeze for YamlHash
impl RefUnwindSafe for YamlHash
impl Send for YamlHash
impl Sync for YamlHash
impl Unpin for YamlHash
impl UnwindSafe for YamlHash
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