Remove unused code and clean up warnings.

This commit is contained in:
Tom Alexander
2020-06-07 13:25:27 -04:00
parent 4ab311c178
commit d06fbea288
13 changed files with 80 additions and 1530 deletions

View File

@@ -312,7 +312,6 @@ impl Loopable for serde_json::Value {
impl CompareContextElement for serde_json::Value {
fn equals(&self, other: &dyn ContextElement) -> bool {
// println!("equals json {:?} | {:?}", self, other);
// Handle other serde_json::Value
match other.to_any().downcast_ref::<Self>() {
None => (),
@@ -340,7 +339,6 @@ impl CompareContextElement for serde_json::Value {
}
fn partial_compare(&self, other: &dyn ContextElement) -> Option<Ordering> {
// println!("partial_compare json {:?} | {:?}", self, other);
// Handle type coerced objects
// When doing a greater than or less than comparison,
@@ -383,9 +381,10 @@ impl CompareContextElement for serde_json::Value {
serde_json::Value::String(other_string),
) => self_string.partial_cmp(other_string),
(
serde_json::Value::Array(self_array),
serde_json::Value::Array(other_array),
serde_json::Value::Array(_self_array),
serde_json::Value::Array(_other_array),
) => {
// TODO: is this reachable given the early convert to string before this block?
return self
.render(&Vec::new())
.unwrap_or("".to_owned())
@@ -393,7 +392,7 @@ impl CompareContextElement for serde_json::Value {
&other_json_value
.render(&Vec::new())
.unwrap_or("".to_owned()),
)
);
}
_ => None,
};
@@ -408,14 +407,14 @@ impl CompareContextElement for serde_json::Value {
}
(
serde_json::Value::String(self_string),
OwnedLiteral::LPositiveInteger(other_num),
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),
OwnedLiteral::LPositiveInteger(_other_num),
) => return compare_json_numbers(self_num, other_literal),
(serde_json::Value::Array(_), _) => {
// TODO
@@ -439,20 +438,6 @@ impl CompareContextElement for serde_json::Value {
}
}
/// Create a new vec by of references to the serde_json::Values as
/// ContextElement trait objects so we can use its implementation of
/// PartialOrd.
///
/// You cannot implement a trait you do not define for a type you do
/// not define, so I cannot implement PartialOrd for
/// serde_json::value. Instead, I just re-use the PartialOrd
/// implementation for ContextElement which unfortunately has extra
/// overhead of downcasting. This would be a good spot for
/// optimization.
fn convert_vec_to_context_element(array: &Vec<serde_json::Value>) -> Vec<&dyn ContextElement> {
array.iter().map(|v| v as _).collect()
}
#[derive(Debug)]
enum JsonNumber {
UnsignedInteger(u64),
@@ -518,10 +503,6 @@ where
{
let self_number: JsonNumber = self_input.into();
let other_number: JsonNumber = other_input.into();
// println!(
// "compare_number_and_string {:?} | {:?}",
// self_number, other_number
// );
// TODO: Figure out how javascript compares floats and ints
match (self_number, other_number) {
(JsonNumber::Failure, _) => return None,
@@ -529,26 +510,25 @@ where
(JsonNumber::UnsignedInteger(self_num), JsonNumber::UnsignedInteger(other_num)) => {
return self_num.partial_cmp(&other_num)
}
(JsonNumber::UnsignedInteger(self_num), JsonNumber::SignedInteger(other_num)) => {
(JsonNumber::UnsignedInteger(_self_num), JsonNumber::SignedInteger(_other_num)) => {
return Some(Ordering::Greater)
}
(JsonNumber::UnsignedInteger(self_num), JsonNumber::Decimal(other_num)) => return None,
(JsonNumber::UnsignedInteger(_self_num), JsonNumber::Decimal(_other_num)) => return None,
(JsonNumber::SignedInteger(self_num), JsonNumber::UnsignedInteger(other_num)) => {
(JsonNumber::SignedInteger(_self_num), JsonNumber::UnsignedInteger(_other_num)) => {
return Some(Ordering::Less)
}
(JsonNumber::SignedInteger(self_num), JsonNumber::SignedInteger(other_num)) => {
return self_num.partial_cmp(&other_num)
}
(JsonNumber::SignedInteger(self_num), JsonNumber::Decimal(other_num)) => return None,
(JsonNumber::SignedInteger(_self_num), JsonNumber::Decimal(_other_num)) => return None,
(JsonNumber::Decimal(self_num), JsonNumber::UnsignedInteger(other_num)) => return None,
(JsonNumber::Decimal(self_num), JsonNumber::SignedInteger(other_num)) => return None,
(JsonNumber::Decimal(_self_num), JsonNumber::UnsignedInteger(_other_num)) => return None,
(JsonNumber::Decimal(_self_num), JsonNumber::SignedInteger(_other_num)) => return None,
(JsonNumber::Decimal(self_num), JsonNumber::Decimal(other_num)) => {
return self_num.partial_cmp(&other_num)
}
}
None
}
#[cfg(test)]