From 46bb5558ac829de7d724a5d62b9e74174670f812 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 10 May 2020 22:26:47 -0400 Subject: [PATCH] Going to a more generic equality comparison for json. --- src/bin.rs | 30 ++++++++++-------------------- 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/src/bin.rs b/src/bin.rs index 9c17df6..5555061 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -143,26 +143,16 @@ impl Loopable for serde_json::Value { impl CompareContextElement for serde_json::Value { fn equals(&self, other: &dyn ContextElement) -> bool { - match self { - 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::() { - None => (), - Some(other_json_value) => return self == other_json_value, - } - // Handle rust string (for string literals) - match other.to_any().downcast_ref::() { - None => (), - Some(other_string) => return string_value == other_string, - } - // Otherwise we know of no other string types - false - } - serde_json::Value::Array(array_value) => false, - serde_json::Value::Object(_obj) => false, + // Handle other serde_json::Value + match other.to_any().downcast_ref::() { + None => (), + Some(other_json_value) => return self == other_json_value, } + // Handle string literals + match other.to_any().downcast_ref::() { + None => (), + Some(other_string) => return self.as_str().map_or(false, |s| s == other_string), + } + false } }