use std::fmt::Display;
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum BinaryOperator {
Equals,
NotEquals,
GreaterThan,
SmallerThan,
GreaterEqual,
SmallerEqual,
Contains,
ContainsCs,
In,
InCs,
StartsWith,
StartsWithCs,
EndsWith,
EndsWithCs,
Plus,
Minus,
}
impl BinaryOperator {
pub fn symbol(&self) -> &'static str {
match self {
BinaryOperator::Equals => "==",
BinaryOperator::NotEquals => "!=",
BinaryOperator::GreaterThan => ">",
BinaryOperator::SmallerThan => "<",
BinaryOperator::GreaterEqual => ">=",
BinaryOperator::SmallerEqual => "<=",
BinaryOperator::Contains => "contains",
BinaryOperator::ContainsCs => "contains_cs",
BinaryOperator::In => "in",
BinaryOperator::InCs => "in_cs",
BinaryOperator::StartsWith => "startswith",
BinaryOperator::StartsWithCs => "startswith_cs",
BinaryOperator::EndsWith => "endswith",
BinaryOperator::EndsWithCs => "endswith_cs",
BinaryOperator::Plus => "+",
BinaryOperator::Minus => "-",
}
}
}
impl Display for BinaryOperator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.symbol())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum LogicalOperator {
And,
Or,
}
impl LogicalOperator {
pub fn symbol(&self) -> &'static str {
match self {
LogicalOperator::And => "&&",
LogicalOperator::Or => "||",
}
}
}
impl Display for LogicalOperator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.symbol())
}
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum UnaryOperator {
Not,
}
impl UnaryOperator {
pub fn symbol(&self) -> &'static str {
match self {
UnaryOperator::Not => "!",
}
}
}
impl Display for UnaryOperator {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(self.symbol())
}
}