Skip to content

Commit a55636e

Browse files
committed
primitives - targeting - eval - Value serialize to serde_json::Value
1 parent fa5f614 commit a55636e

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

primitives/src/targeting/eval.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ impl Rule {
8383
}
8484

8585
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
86-
#[serde(try_from = "SerdeValue")]
86+
#[serde(try_from = "SerdeValue", into = "SerdeValue")]
8787
pub enum Value {
8888
Bool(bool),
8989
Number(Number),
@@ -124,6 +124,18 @@ impl TryFrom<SerdeValue> for Value {
124124
}
125125
}
126126

127+
impl Into<SerdeValue> for Value {
128+
fn into(self) -> SerdeValue {
129+
match self {
130+
Value::Bool(bool) => SerdeValue::Bool(bool),
131+
Value::Number(number) => SerdeValue::Number(number),
132+
Value::String(string) => SerdeValue::String(string),
133+
Value::Array(array) => SerdeValue::Array(array.into_iter().map(|value| value.into()).collect()),
134+
Value::BigNum(bignum) => SerdeValue::String(bignum.to_string())
135+
}
136+
}
137+
}
138+
127139
#[derive(Debug, Serialize, Deserialize, Clone, PartialEq, Eq)]
128140
#[serde(rename_all = "camelCase")]
129141
// TODO: https://github.com/AdExNetwork/adex-validator-stack-rust/issues/296

0 commit comments

Comments
 (0)