Fixed greater than helper by using rust's PartialOrd implementation for Vec.
This commit is contained in:
parent
7126e83d9a
commit
f640cb0440
16
src/bin.rs
16
src/bin.rs
@ -220,7 +220,7 @@ impl CompareContextElement for serde_json::Value {
|
|||||||
serde_json::Value::String(self_string),
|
serde_json::Value::String(self_string),
|
||||||
serde_json::Value::String(other_string),
|
serde_json::Value::String(other_string),
|
||||||
) => self_string.partial_cmp(other_string),
|
) => self_string.partial_cmp(other_string),
|
||||||
// TODO: Non-scalar types
|
(serde_json::Value::Array(self_array), serde_json::Value::Array(other_array)) => convert_vec_to_context_element(self_array).partial_cmp(&convert_vec_to_context_element(other_array)),
|
||||||
_ => None,
|
_ => None,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -242,3 +242,17 @@ impl CompareContextElement for serde_json::Value {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 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()
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user