Added val() function to KeyTreeRef.

[?]
Jun 28, 2021, 7:35 AM
BRO5BHI2M7DT5ERR5TXETFDJCE2XCFK7XGBWVJEFDK6LCHCIZKUAC

Dependencies

Change contents

  • edit in src/lib.rs at line 3
    [4.18483]
    [4.18483]
    use std::str::FromStr;
  • replacement in src/lib.rs at line 161
    [4.23214][4.23214:23246]()
    return Some(())
    [4.23214]
    [4.23246]
    Some(())
    },
    None => None,
    }
    }
    fn peek(&self) -> Option<()> {
    match self.top_token().next() {
    Some(_) => Some(()),
    None => None,
    }
    }
    pub fn assert_unique_top_token(&self) -> Result<()> {
    match self.peek() {
    None => Ok(()),
    _ => Err(Error::new(ErrorKind::EUniqueTokenFMany)),
    }
    }
    pub fn val<T>(&self, key_path: &str) -> Result<T>
    where
    T: FromStr,
    KeyTreeRef<'a>: TryInto<T>,
    KeyTreeRef<'a>: TryInto<T, Error = Error>,
    {
    let path = KeyPath::from_str(key_path);
    let kt = self.recurse(&path)?;
    kt.assert_unique_top_token()?;
    match kt.top_token() {
    Token::KeyValue { key, value, .. } => {
    match T::from_str(value) {
    Ok(t) => Ok(t),
    Err(err) => {
    Err(Error::new(ErrorKind::FromStr(
    format!("{}: {}", key, value),
    format!("{}", kt.1),
    )))
    },
    }
  • replacement in src/lib.rs at line 202
    [4.23261][4.23261:23294]()
    None => return None,
    [4.23261]
    [4.23294]
    _ => Err(Error::new(ErrorKind::EUniqueTokenFMany)),
  • edit in src/lib.rs at line 206
    [4.23311]
    [4.4102]
  • replacement in src/lib.rs at line 216
    [4.23672][4.23672:23753](),[4.23753][2.338:373](),[2.373][4.23820:23894](),[4.23820][4.23820:23894]()
    // Check that top token is unique
    match kt.top_token().next() {
    None => kt.try_into(),
    _ => Err(Error::new(ErrorKind::EUniqueTokenFMany)),
    }
    [4.23672]
    [4.23894]
    kt.assert_unique_top_token()?;
    kt.try_into()
  • replacement in src/into.rs at line 63
    [4.30331][4.30331:30404]()
    Err(Error::new(ErrorKind::FailedFromStr(
    [4.30331]
    [4.30404]
    Err(Error::new(ErrorKind::FromStr(
  • edit in src/into.rs at line 66
    [4.30543][4.30543:30602]()
    into_type.to_string(),
  • replacement in src/error.rs at line 55
    [4.37700][4.37700:37842]()
    // `FromStr(value)` failed (key/value pair as string, position as string, into_type as string)
    FailedFromStr(String, String, String),
    [4.37700]
    [4.37842]
    // `FromStr(keyval, pos)
    FromStr(String, String),
  • replacement in src/error.rs at line 116
    [4.39429][4.39429:39490]()
    ErrorKind::FailedFromStr(_, _, _) => None,
    [4.39429]
    [4.39490]
    ErrorKind::FromStr(_, _) => None,
  • replacement in src/error.rs at line 148
    [3.5966][3.5966:6031]()
    ErrorKind::FailedFromStr(token, pos, into_type) => {
    [3.5966]
    [3.6031]
    ErrorKind::FromStr(token, pos) => {
  • replacement in src/error.rs at line 151
    [3.6078][3.6078:6189]()
    "Error: Couldn't read string into type {} at {}: \"{}\".",
    into_type,
    [3.6078]
    [3.6189]
    "Error: Couldn't parse string at {}: \"{}\".",
  • edit in src/error.rs at line 179
    [4.41005][4.41005:41315]()
    ErrorKind::FailedFromStr(token, pos, into_type) => {
    write!(
    f,
    "Error: Couldn't read string into type {} at {}: \"{}\".",
    into_type,
    pos,
    token,
    )
    },
  • replacement in src/error.rs at line 393
    [4.46474][4.46474:46561]()
    ErrorKind::FailedFromStr(String::new(), String::new(), String::new()),
    [4.46474]
    [4.46561]
    ErrorKind::FromStr(String::new(), String::new(), String::new()),
  • replacement in examples/hobbit/src/main.rs at line 31
    [4.49495][4.6601:6695]()
    name: self.at("hobbit::name")?,
    age: self.at("hobbit::age")?,
    [4.49495]
    [4.6695]
    name: self.val("hobbit::name")?,
    age: self.val("hobbit::age")?,