#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Term {
Default { value: Value },
Field {
field: String,
value: Value,
},
Negate { term: Box<Term> },
Combine {
left: Box<Term>,
right: Box<Term>,
operator: Operator,
},
}
impl Term {
pub const fn new_default(value: Value) -> Self {
Self::Default { value }
}
pub const fn new_negate(term: Box<Term>) -> Self {
Self::Negate { term }
}
pub fn visit<T>(self, visitor: impl Fn(Term, &dyn Fn(Box<Term>) -> T) -> T) -> T {
#[inline(always)]
fn inner<T>(term: Term, visitor: &dyn Fn(Term, &dyn Fn(Box<Term>) -> T) -> T) -> T {
visitor(term, &|node| node.visit(visitor))
}
inner(self, &visitor)
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Operator {
#[doc(alias = "intersection")]
And,
#[doc(alias = "union")]
Or,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Primitive {
Text(String),
Integer(i64),
Boolean(bool),
}
impl From<String> for Primitive {
fn from(value: String) -> Self {
Self::Text(value)
}
}
impl From<i64> for Primitive {
fn from(value: i64) -> Self {
Self::Integer(value)
}
}
impl From<bool> for Primitive {
fn from(value: bool) -> Self {
Self::Boolean(value)
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum Value {
Primitive(Primitive),
Range(Boundary, Boundary),
}
impl<T: Into<Primitive>> From<T> for Value {
fn from(value: T) -> Self {
Value::Primitive(value.into())
}
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum BoundaryKind {
Inclusive,
Exclusive,
}
#[derive(Debug, Clone, Eq, PartialEq)]
pub struct Boundary {
pub value: i64,
pub kind: BoundaryKind,
}