Skip to content

Commit d450bad

Browse files
authored
feat: add conversion from &serde_json::Value (#46)
Signed-off-by: YUE Daian <sheepduke@gmail.com>
1 parent 9979f00 commit d450bad

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/serde_json.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,14 @@ impl TryFrom<serde_json::Value> for Value {
88
}
99
}
1010

11+
impl TryFrom<&serde_json::Value> for Value {
12+
type Error = EvaluationError;
13+
14+
fn try_from(value: &serde_json::Value) -> Result<Self, Self::Error> {
15+
json_value_to_value(value)
16+
}
17+
}
18+
1119
fn json_value_to_value(value: &serde_json::Value) -> EvaluationResult<Value> {
1220
match value {
1321
serde_json::Value::Bool(value) => Ok(Value::Bool(*value)),
@@ -96,9 +104,8 @@ mod tests {
96104
),
97105
);
98106

99-
let actual_value: Value = json.try_into().unwrap();
100-
101-
assert_eq!(expected_value, actual_value);
107+
assert_eq!(expected_value, Value::try_from(&json).unwrap());
108+
assert_eq!(expected_value, Value::try_from(json).unwrap());
102109
}
103110

104111
#[test]

0 commit comments

Comments
 (0)