Implement partial_compare for OwnedLiteral.
This commit is contained in:
parent
bf35fd0ae4
commit
16d8891452
@ -204,8 +204,36 @@ impl CompareContextElement for OwnedLiteral {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn partial_compare(&self, other: &dyn ContextElement) -> Option<Ordering> {
|
fn partial_compare(&self, other: &dyn ContextElement) -> Option<Ordering> {
|
||||||
// TODO
|
println!("partial_compare literal {:?} | {:?}", self, other);
|
||||||
None
|
// If its an OwnedLiteral then compare them directly,
|
||||||
|
// otherwise defer to the other type's implementation of
|
||||||
|
// CompareContextElement since the end user could add any
|
||||||
|
// type.
|
||||||
|
match other.to_any().downcast_ref::<Self>() {
|
||||||
|
None => match other.partial_compare(self) {
|
||||||
|
None => None,
|
||||||
|
Some(ord) => match ord {
|
||||||
|
Ordering::Equal => Some(Ordering::Equal),
|
||||||
|
Ordering::Greater => Some(Ordering::Less),
|
||||||
|
Ordering::Less => Some(Ordering::Greater),
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Some(other_literal) => match (self, other_literal) {
|
||||||
|
(OwnedLiteral::LString(self_text), OwnedLiteral::LString(other_text)) => {
|
||||||
|
self_text.partial_cmp(other_text)
|
||||||
|
}
|
||||||
|
(OwnedLiteral::LPositiveInteger(self_num), OwnedLiteral::LString(other_text)) => {
|
||||||
|
self_num.to_string().partial_cmp(other_text)
|
||||||
|
}
|
||||||
|
(OwnedLiteral::LString(self_text), OwnedLiteral::LPositiveInteger(other_num)) => {
|
||||||
|
self_text.partial_cmp(&other_num.to_string())
|
||||||
|
}
|
||||||
|
(
|
||||||
|
OwnedLiteral::LPositiveInteger(self_num),
|
||||||
|
OwnedLiteral::LPositiveInteger(other_num),
|
||||||
|
) => self_num.partial_cmp(other_num),
|
||||||
|
},
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user