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