Going to a more generic equality comparison for json.

This commit is contained in:
Tom Alexander 2020-05-10 22:26:47 -04:00
parent 6297fa0189
commit 46bb5558ac
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -143,26 +143,16 @@ impl Loopable for serde_json::Value {
impl CompareContextElement for serde_json::Value { impl CompareContextElement for serde_json::Value {
fn equals(&self, other: &dyn ContextElement) -> bool { fn equals(&self, other: &dyn ContextElement) -> bool {
match self { // Handle other serde_json::Value
serde_json::Value::Null => false,
serde_json::Value::Bool(boolean) => false,
serde_json::Value::Number(_num) => false,
serde_json::Value::String(string_value) => {
// Handle json string
match other.to_any().downcast_ref::<Self>() { match other.to_any().downcast_ref::<Self>() {
None => (), None => (),
Some(other_json_value) => return self == other_json_value, Some(other_json_value) => return self == other_json_value,
} }
// Handle rust string (for string literals) // Handle string literals
match other.to_any().downcast_ref::<String>() { match other.to_any().downcast_ref::<String>() {
None => (), None => (),
Some(other_string) => return string_value == other_string, Some(other_string) => return self.as_str().map_or(false, |s| s == other_string),
} }
// Otherwise we know of no other string types
false false
} }
serde_json::Value::Array(array_value) => false,
serde_json::Value::Object(_obj) => false,
}
}
} }