From 9851a2556dbf24516bdb6ec3548fc34b9fa91875 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sat, 16 May 2020 13:40:56 -0400 Subject: [PATCH] Ordering implementation for comparison between json and literals. --- src/bin.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/bin.rs b/src/bin.rs index c72d00d..7e41d8d 100644 --- a/src/bin.rs +++ b/src/bin.rs @@ -161,7 +161,25 @@ impl CompareContextElement for serde_json::Value { } fn partial_compare(&self, other: &dyn ContextElement) -> Option { - // TODO: Implement + // Handle other serde_json::Value + match other.to_any().downcast_ref::() { + None => (), + Some(other_json_value) => return None, // TODO: Implement + } + // Handle string literals + match other.to_any().downcast_ref::() { + 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::() { + None => (), + Some(other_num) => return self.as_u64().map_or(None, |n| n.partial_cmp(other_num)), + } None } }