Made some functions pub (crate). Added opt_vec_value() fn. Improved docs.
[?]
CrEcTsRjb1hHQjHuumqRfqdbVV4X58iLEubi4noaDPFa
Jul 25, 2021, 3:15 AM
INHPVRSEBO7L5SRI3BBY6CU4PAXI2FCGCX2FOIYQHOTTLMZMMR3ACDependencies
- [2]
WPR2A6Y7Fixed bug in parser. Added opt_vec_at() fn. - [3]
6ZJX2OQVFirst commit - [4]
QMBJ2BAZCan now handle FromStr. - [5]
3K5KIVGXCleaned up docs. - [6]
MRTKABARCleaned up some docs. - [7]
N467KW7JRefactored (simplified) errors. - [8]
YJVNXWNHminor - [9]
BRO5BHI2Added val() function to KeyTreeRef. - [10]
446EWE33Added key_into() function.
Change contents
- replacement in src/lib.rs at line 172
pub struct KeyPath {pub (crate) struct KeyPath { - replacement in src/lib.rs at line 199
pub(crate) fn from_str(s: &str) -> Self {pub (crate) fn from_str(s: &str) -> Self { - edit in src/lib.rs at line 324
/// Returns the key name of the top token.pub fn name(&self) -> String {self.tokens[0].key().to_string()} - replacement in src/lib.rs at line 329
pub fn siblings(&self, index: usize) -> Vec<usize> {pub (crate) fn siblings(&self, index: usize) -> Vec<usize> { - replacement in src/lib.rs at line 398
pub fn key_into<T>(self) -> Result<T>pub (crate) fn key_into<T>(self) -> Result<T> - replacement in src/lib.rs at line 407
pub fn keyvalue_into<T>(&self) -> Result<T>pub (crate) fn keyvalue_into<T>(&self) -> Result<T> - edit in src/lib.rs at line 418
/// Returns a `Some<KeyTree>` if the path exists or `None` otherwise. - edit in src/lib.rs at line 433
/// Returns a `KeyTree`. - edit in src/lib.rs at line 448
/// Returns a `T: FromStr` where `T` is the receiver type./// ```/// use std::convert::TryInto;/// use keytree::{KeyTree, KeyTreeRef};/// use keytree::Error;////// static TEMP: &'static str = r#"example:/// temp: -15.3"#;////// struct Temperature(f32);////// impl FromStr for Temperature {/// let Err = std::num::ParseFloatError;////// fn from_str(s: &str) -> Result<Self, Self::Err> {/// self.parse(s)/// }/// }////// impl<'a> TryInto<Temperature> for KeyTreeRef<'a> {/// type Error = Error;////// fn try_into(self) -> Result<Hobbit, Error> {/// Ok(Temperature(self.value("example::temp")?))/// }/// }////// fn main() {/// let kt = KeyTree::parse(TEMP).unwrap();/// let temp: Temperature = kt.to_ref().try_into().unwrap();/// }/// ``` - edit in src/lib.rs at line 493
/// Returns an `Option<T: FromStr>` where `Option<T>` is the receiver type. Returns `None` if/// the path does not exist. - edit in src/lib.rs at line 508
/// Returns a `Vec<T: FromStr>` where `Vec<T>` is the receiver type. Expects at least one/// key-value. Use `opt_vec_value` if an empty `Vec` is permissible. - edit in src/lib.rs at line 511
whereT: FromStr,{let path = KeyPath::from_str(key_path);let kts = self.resolve_path(&path)?;let mut v = Vec::new();for kt in kts {v.push(kt.keyvalue_into()?)}if v.is_empty() {return Err(expected_non_empty_collection(file!(),line!(),key_path))};Ok(v)}/// Returns a `Vec<T: FromStr>` where `Vec<T>` is the receiver type. The `Vec` can be empty.pub fn opt_vec_value<T>(&self, key_path: &str) -> Result<Vec<T>> - edit in src/lib.rs at line 546
/// Returns a `Vec<T>` where `T` can be coerced from a KeyTree. Fails if the path does not/// exist. - edit in src/lib.rs at line 570
/// Returns a `Vec<T>` where `T` can be coerced from a KeyTree. If the path does not exist/// returns an empty `Vec`. - replacement in src/lib.rs at line 588
pub fn resolve_path(self, key_path: &KeyPath) -> Result<Vec<Self>> {pub (crate) fn resolve_path(self, key_path: &KeyPath) -> Result<Vec<Self>> { - replacement in examples/hobbit/src/main.rs at line 33
friends: self.vec_at("hobbit::friends::hobbit")?,friends: self.opt_vec_at("hobbit::friends::hobbit")?,