Ordering implementation for comparison between json and literals.
This commit is contained in:
parent
8748cb7063
commit
9851a2556d
20
src/bin.rs
20
src/bin.rs
@ -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
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user