Add ValueWrapper to Parser - Part 2
@@ -99,15 +99,16 @@ impl Parser {
.collect()
}
- pub fn parse_value<'o>(&'o self, value: &'o Value) -> Option<Cow<'o, Value>> {
+ pub fn parse_value<'o, V: Into<ValueWrapper<'o>>>(&'o self, value: V) -> Option<Cow<'o, Value>> {
match self {
Parser::Exp { keys } => {
+ let value = value.into();
let mut temp_value = Some(value);
let mut count = 0;
while count < keys.len() && temp_value.is_some() {
- temp_value = temp_value.and_then(|val| keys[count].get(val));
+ temp_value = temp_value.and_then(|val| keys[count].get(&val)).map(|val| val.into());
count += 1;
}
@@ -145,7 +146,7 @@ pub enum ValueGetter {
}
impl ValueGetter {
- pub fn get<'o>(&self, value: &'o Value) -> Option<&'o Value> {
+ pub fn get<'o>(&self, value: &'o ValueWrapper<'o>) -> Option<&'o Value> {
match self {
ValueGetter::Map { key } => value.get_from_map(key),
ValueGetter::Array { index } => value.get_from_array(*index),
@@ -213,7 +214,7 @@ mod test {
"#;
// Act
- let value = serde_json::from_str(json).unwrap();
+ let value: Value = serde_json::from_str(json).unwrap();
let result = parser.parse_value(&value);
// Assert
@@ -234,7 +235,7 @@ mod test {
"#;
// Act
- let value = serde_json::from_str(json).unwrap();
+ let value: Value = serde_json::from_str(json).unwrap();
let result = parser.parse_value(&value);
// Assert
