Made some functions pub (crate). Added opt_vec_value() fn. Improved docs.

[?]
CrEcTsRjb1hHQjHuumqRfqdbVV4X58iLEubi4noaDPFa
Jul 25, 2021, 3:15 AM
INHPVRSEBO7L5SRI3BBY6CU4PAXI2FCGCX2FOIYQHOTTLMZMMR3AC

Dependencies

Change contents

  • replacement in src/lib.rs at line 172
    [3.773][3.773:794]()
    pub struct KeyPath {
    [3.773]
    [3.794]
    pub (crate) struct KeyPath {
  • replacement in src/lib.rs at line 199
    [3.1473][3.1473:1519]()
    pub(crate) fn from_str(s: &str) -> Self {
    [3.1473]
    [3.1519]
    pub (crate) fn from_str(s: &str) -> Self {
  • edit in src/lib.rs at line 324
    [3.22316][3.22316:22446]()
    /// 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
    [3.2472][3.2472:2529]()
    pub fn siblings(&self, index: usize) -> Vec<usize> {
    [3.2472]
    [3.2529]
    pub (crate) fn siblings(&self, index: usize) -> Vec<usize> {
  • replacement in src/lib.rs at line 398
    [3.48][3.48:90]()
    pub fn key_into<T>(self) -> Result<T>
    [3.48]
    [3.90]
    pub (crate) fn key_into<T>(self) -> Result<T>
  • replacement in src/lib.rs at line 407
    [3.454][3.4324:4372]()
    pub fn keyvalue_into<T>(&self) -> Result<T>
    [3.454]
    [3.4372]
    pub (crate) fn keyvalue_into<T>(&self) -> Result<T>
  • edit in src/lib.rs at line 418
    [3.4598]
    [3.4598]
    /// Returns a `Some<KeyTree>` if the path exists or `None` otherwise.
  • edit in src/lib.rs at line 433
    [3.23311]
    [3.4890]
    /// Returns a `KeyTree`.
  • edit in src/lib.rs at line 448
    [3.1257]
    [3.5362]
    /// 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
    [3.5776]
    [3.5776]
    /// 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
    [3.6156]
    [3.6156]
    /// 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
    [3.6221]
    [3.6221]
    where
    T: 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
    [3.6478]
    [3.6478]
    /// 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
    [2.3466]
    [2.3466]
    /// 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
    [3.6813][3.6813:6886]()
    pub fn resolve_path(self, key_path: &KeyPath) -> Result<Vec<Self>> {
    [3.6813]
    [3.24404]
    pub (crate) fn resolve_path(self, key_path: &KeyPath) -> Result<Vec<Self>> {
  • replacement in examples/hobbit/src/main.rs at line 33
    [3.13877][3.13877:13946]()
    friends: self.vec_at("hobbit::friends::hobbit")?,
    [3.13877]
    [3.13946]
    friends: self.opt_vec_at("hobbit::friends::hobbit")?,