Skip to content

Commit

Permalink
feat: add conversion from &serde_json::Value (#46)
Browse files Browse the repository at this point in the history
Signed-off-by: YUE Daian <[email protected]>
  • Loading branch information
sheepduke authored Dec 19, 2023
1 parent 9979f00 commit d450bad
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions src/serde_json.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,14 @@ impl TryFrom<serde_json::Value> for Value {
}
}

impl TryFrom<&serde_json::Value> for Value {
type Error = EvaluationError;

fn try_from(value: &serde_json::Value) -> Result<Self, Self::Error> {
json_value_to_value(value)
}
}

fn json_value_to_value(value: &serde_json::Value) -> EvaluationResult<Value> {
match value {
serde_json::Value::Bool(value) => Ok(Value::Bool(*value)),
Expand Down Expand Up @@ -96,9 +104,8 @@ mod tests {
),
);

let actual_value: Value = json.try_into().unwrap();

assert_eq!(expected_value, actual_value);
assert_eq!(expected_value, Value::try_from(&json).unwrap());
assert_eq!(expected_value, Value::try_from(json).unwrap());
}

#[test]
Expand Down

0 comments on commit d450bad

Please sign in to comment.