For partial_cmp, convert OwnedLiterals into serde_json values.
This commit is contained in:
parent
a378d6e6f3
commit
5b656a44ad
62
src/bin.rs
62
src/bin.rs
@ -332,7 +332,18 @@ impl CompareContextElement for serde_json::Value {
|
||||
return self.as_str().map_or(false, |s| s == other_string)
|
||||
}
|
||||
Some(OwnedLiteral::LPositiveInteger(other_num)) => {
|
||||
return self.as_u64().map_or(false, |n| n == *other_num)
|
||||
let other_json_num: serde_json::Number = std::convert::From::from(*other_num);
|
||||
return self
|
||||
.equals(&serde_json::Value::Number(other_json_num) as &dyn ContextElement);
|
||||
}
|
||||
Some(OwnedLiteral::LFloat(other_num)) => {
|
||||
let other_json_num = serde_json::Number::from_f64(*other_num);
|
||||
match other_json_num {
|
||||
None => return false,
|
||||
Some(ojn) => {
|
||||
return self.equals(&serde_json::Value::Number(ojn) as &dyn ContextElement)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
false
|
||||
@ -401,39 +412,24 @@ impl CompareContextElement for serde_json::Value {
|
||||
// Handle literals
|
||||
match other.to_any().downcast_ref::<OwnedLiteral>() {
|
||||
None => (),
|
||||
Some(other_literal) => match (self, other_literal) {
|
||||
(serde_json::Value::String(self_string), OwnedLiteral::LString(other_string)) => {
|
||||
return self_string.partial_cmp(other_string)
|
||||
Some(OwnedLiteral::LString(text)) => {
|
||||
return self.to_string().partial_cmp(text);
|
||||
}
|
||||
Some(OwnedLiteral::LPositiveInteger(other_num)) => {
|
||||
let other_json_num: serde_json::Number = std::convert::From::from(*other_num);
|
||||
return self.partial_compare(
|
||||
&serde_json::Value::Number(other_json_num) as &dyn ContextElement
|
||||
);
|
||||
}
|
||||
Some(OwnedLiteral::LFloat(other_num)) => {
|
||||
let other_json_num = serde_json::Number::from_f64(*other_num);
|
||||
match other_json_num {
|
||||
None => return None,
|
||||
Some(ojn) => return self
|
||||
.partial_compare(&serde_json::Value::Number(ojn) as &dyn ContextElement),
|
||||
}
|
||||
(
|
||||
serde_json::Value::String(self_string),
|
||||
OwnedLiteral::LPositiveInteger(_other_num),
|
||||
) => return compare_json_numbers(self_string, other_literal),
|
||||
(serde_json::Value::Number(self_num), OwnedLiteral::LString(other_string)) => {
|
||||
return compare_json_numbers(self_num, other_string)
|
||||
}
|
||||
(
|
||||
serde_json::Value::Number(self_num),
|
||||
OwnedLiteral::LPositiveInteger(_other_num),
|
||||
) => return compare_json_numbers(self_num, other_literal),
|
||||
(serde_json::Value::Array(_), _) => {
|
||||
// TODO
|
||||
todo!()
|
||||
}
|
||||
(serde_json::Value::Object(_), _) => {
|
||||
// TODO
|
||||
todo!()
|
||||
}
|
||||
(serde_json::Value::Bool(_), _) => {
|
||||
// TODO
|
||||
todo!()
|
||||
}
|
||||
(serde_json::Value::Null, _) => {
|
||||
// TODO
|
||||
todo!()
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
};
|
||||
None
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user