Structure for ordering, need to implement for serde_json::Value.

This commit is contained in:
Tom Alexander
2020-05-16 13:31:52 -04:00
parent 8a44bc6fd9
commit 8748cb7063
3 changed files with 55 additions and 2 deletions

View File

@@ -2,7 +2,7 @@ use crate::parser::Filter;
use crate::renderer::errors::RenderError;
use crate::renderer::errors::WalkError;
use std::any::Any;
use std::fmt::Debug;
use std::{cmp::Ordering, fmt::Debug};
pub trait ContextElement:
Debug + Walkable + Renderable + Loopable + CloneIntoBoxedContextElement + CompareContextElement
@@ -36,6 +36,8 @@ pub trait CastToAny {
pub trait CompareContextElement: CastToAny {
fn equals(&self, other: &dyn ContextElement) -> bool;
fn partial_compare(&self, other: &dyn ContextElement) -> Option<Ordering>;
}
pub trait CloneIntoBoxedContextElement {
@@ -59,3 +61,9 @@ impl<'a, 'b> PartialEq<&'b dyn ContextElement> for &'a dyn ContextElement {
self.equals(*other)
}
}
impl<'a, 'b> PartialOrd<&'b dyn ContextElement> for &'a dyn ContextElement {
fn partial_cmp(&self, other: &&'b dyn ContextElement) -> Option<Ordering> {
self.partial_compare(*other)
}
}