Implemented float literals for OwnedLiterals, not yet for serde_json.
This commit is contained in:
@@ -137,6 +137,7 @@ impl Truthiness for OwnedLiteral {
|
||||
match self {
|
||||
OwnedLiteral::LString(text) => !text.is_empty(),
|
||||
OwnedLiteral::LPositiveInteger(_num) => true,
|
||||
OwnedLiteral::LFloat(_num) => true,
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -146,6 +147,7 @@ impl Renderable for OwnedLiteral {
|
||||
match self {
|
||||
OwnedLiteral::LString(text) => Ok(text.clone()),
|
||||
OwnedLiteral::LPositiveInteger(num) => Ok(num.to_string()),
|
||||
OwnedLiteral::LFloat(num) => Ok(num.to_string()),
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,10 +182,25 @@ impl CompareContextElement for OwnedLiteral {
|
||||
(OwnedLiteral::LString(self_text), OwnedLiteral::LPositiveInteger(other_num)) => {
|
||||
self_text == &other_num.to_string()
|
||||
}
|
||||
(OwnedLiteral::LFloat(self_num), OwnedLiteral::LString(other_text)) => {
|
||||
&self_num.to_string() == other_text
|
||||
}
|
||||
(OwnedLiteral::LString(self_text), OwnedLiteral::LFloat(other_num)) => {
|
||||
self_text == &other_num.to_string()
|
||||
}
|
||||
(
|
||||
OwnedLiteral::LPositiveInteger(self_num),
|
||||
OwnedLiteral::LPositiveInteger(other_num),
|
||||
) => self_num == other_num,
|
||||
(OwnedLiteral::LFloat(self_num), OwnedLiteral::LFloat(other_num)) => {
|
||||
self_num == other_num
|
||||
}
|
||||
(OwnedLiteral::LFloat(self_num), OwnedLiteral::LPositiveInteger(other_num)) => {
|
||||
*self_num == (*other_num as f64)
|
||||
}
|
||||
(OwnedLiteral::LPositiveInteger(self_num), OwnedLiteral::LFloat(other_num)) => {
|
||||
(*self_num as f64) == *other_num
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
@@ -212,10 +229,25 @@ impl CompareContextElement for OwnedLiteral {
|
||||
(OwnedLiteral::LString(self_text), OwnedLiteral::LPositiveInteger(other_num)) => {
|
||||
self_text.partial_cmp(&other_num.to_string())
|
||||
}
|
||||
(OwnedLiteral::LFloat(self_num), OwnedLiteral::LString(other_text)) => {
|
||||
self_num.to_string().partial_cmp(other_text)
|
||||
}
|
||||
(OwnedLiteral::LString(self_text), OwnedLiteral::LFloat(other_num)) => {
|
||||
self_text.partial_cmp(&other_num.to_string())
|
||||
}
|
||||
(
|
||||
OwnedLiteral::LPositiveInteger(self_num),
|
||||
OwnedLiteral::LPositiveInteger(other_num),
|
||||
) => self_num.partial_cmp(other_num),
|
||||
(OwnedLiteral::LFloat(self_num), OwnedLiteral::LFloat(other_num)) => {
|
||||
self_num.partial_cmp(other_num)
|
||||
}
|
||||
(OwnedLiteral::LPositiveInteger(self_num), OwnedLiteral::LFloat(other_num)) => {
|
||||
(*self_num as f64).partial_cmp(other_num)
|
||||
}
|
||||
(OwnedLiteral::LFloat(self_num), OwnedLiteral::LPositiveInteger(other_num)) => {
|
||||
self_num.partial_cmp(&(*other_num as f64))
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user