Ordering implementation for comparison between json and literals.

This commit is contained in:
Tom Alexander 2020-05-16 13:40:56 -04:00
parent 8748cb7063
commit 9851a2556d
Signed by: talexander
GPG Key ID: D3A179C9A53C0EDE

View File

@ -161,7 +161,25 @@ impl CompareContextElement for serde_json::Value {
} }
fn partial_compare(&self, other: &dyn ContextElement) -> Option<Ordering> { fn partial_compare(&self, other: &dyn ContextElement) -> Option<Ordering> {
// TODO: Implement // Handle other serde_json::Value
match other.to_any().downcast_ref::<Self>() {
None => (),
Some(other_json_value) => return None, // TODO: Implement
}
// Handle string literals
match other.to_any().downcast_ref::<String>() {
None => (),
Some(other_string) => {
return self
.as_str()
.map_or(None, |s| s.partial_cmp(other_string.as_str()))
}
}
// Handle numeric literals
match other.to_any().downcast_ref::<u64>() {
None => (),
Some(other_num) => return self.as_u64().map_or(None, |n| n.partial_cmp(other_num)),
}
None None
} }
} }