mod operand_type;
mod size;
pub(crate) use self::operand_type::OperandType;
pub use self::size::Size;
use core::fmt;
use crate::condition::{
equal, greater_than, greater_than_or_equal, less_than, less_than_or_equal, not_equal, Between,
Condition, In,
};
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct Operand {
pub(crate) op: OperandType,
}
impl Operand {
pub fn equal<T>(self, right: T) -> Condition
where
T: Into<Operand>,
{
equal(self, right).into()
}
pub fn not_equal<T>(self, right: T) -> Condition
where
T: Into<Operand>,
{
not_equal(self, right).into()
}
pub fn greater_than<T>(self, right: T) -> Condition
where
T: Into<Operand>,
{
greater_than(self, right).into()
}
pub fn greater_than_or_equal<T>(self, right: T) -> Condition
where
T: Into<Operand>,
{
greater_than_or_equal(self, right).into()
}
pub fn less_than<T>(self, right: T) -> Condition
where
T: Into<Operand>,
{
less_than(self, right).into()
}
pub fn less_than_or_equal<T>(self, right: T) -> Condition
where
T: Into<Operand>,
{
less_than_or_equal(self, right).into()
}
pub fn between<L, U>(self, lower: L, upper: U) -> Condition
where
L: Into<Operand>,
U: Into<Operand>,
{
Condition::Between(Between {
op: self,
lower: lower.into(),
upper: upper.into(),
})
}
pub fn in_<I, T>(self, items: I) -> Condition
where
I: IntoIterator<Item = T>,
T: Into<Operand>,
{
Condition::In(In::new(self, items))
}
}
impl fmt::Display for Operand {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
self.op.fmt(f)
}
}
impl<T> From<T> for Operand
where
T: Into<OperandType>,
{
fn from(op: T) -> Self {
Self { op: op.into() }
}
}