#[non_exhaustive]pub enum Predicate {
Show 16 variants
And(Vec<Predicate>),
Or(Vec<Predicate>),
Not(Box<Predicate>),
IsNull(String),
IsNotNull(String),
IsTrue(String),
IsFalse(String),
Number {
field: String,
op: Compare,
value: f64,
},
NumberIn {
field: String,
values: Vec<f64>,
},
Between {
field: String,
low: f64,
high: f64,
},
Text {
field: String,
op: TextCompare,
value: String,
},
TextIn {
field: String,
values: Vec<String>,
},
Contains {
field: String,
value: AttrValue,
},
ContainsAny {
field: String,
values: Vec<AttrValue>,
},
ContainsAll {
field: String,
values: Vec<AttrValue>,
},
IsEmpty(String),
}Expand description
A condition over a document’s attributes.
Fields are named as the namespace’s AttrSchema declares them, and an
operator has to fit the field’s type: a wrong one is refused by
Namespace::filter before any read, never an
empty result.
The serialized form is derived from the type and is not a promised format.
§Examples
use itzma_core::{Compare, Predicate};
// active is true and price is under 20
let p = Predicate::and(vec![
Predicate::is_true("active"),
Predicate::number("price", Compare::Lt, 20.0),
]);Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
And(Vec<Predicate>)
Every condition holds. At least one is required.
Or(Vec<Predicate>)
At least one condition holds. At least one is required.
Not(Box<Predicate>)
The condition does not hold. A null field makes most conditions false, so this matches it.
IsNull(String)
The field is missing or null. Any type.
IsNotNull(String)
The field has a value. Any type.
IsTrue(String)
A bool field is true.
IsFalse(String)
A bool field is false.
Number
A number field compared with a value.
NumberIn
A number field equals one of the values.
Between
A number field is between low and high, both included.
Fields
Text
A string field compared with a value.
TextIn
A string field equals one of the values.
Contains
A set field holds the element.
Fields
ContainsAny
A set field holds at least one of the elements.
ContainsAll
A set field holds every one of the elements.
IsEmpty(String)
A set field is present and has no elements. A null field is not empty.
Implementations§
Source§impl Predicate
impl Predicate
Sourcepub fn number(field: impl Into<String>, op: Compare, value: f64) -> Self
pub fn number(field: impl Into<String>, op: Compare, value: f64) -> Self
A number field compared with value.
Sourcepub fn text(
field: impl Into<String>,
op: TextCompare,
value: impl Into<String>,
) -> Self
pub fn text( field: impl Into<String>, op: TextCompare, value: impl Into<String>, ) -> Self
A string field compared with value.
Sourcepub fn negate(inner: Predicate) -> Self
pub fn negate(inner: Predicate) -> Self
The condition does not hold. Named negate because not is
std::ops::Not’s method.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for Predicate
impl<'de> Deserialize<'de> for Predicate
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
impl StructuralPartialEq for Predicate
Auto Trait Implementations§
impl Forget for Predicate
impl Freeze for Predicatewhere
*const u8 is !null: Freeze,
PhantomData<Predicate>: Freeze,
*const Predicate is !null: Freeze,
PhantomData<u8>: Freeze,
PhantomData<f64>: Freeze,
PhantomData<String>: Freeze,
PhantomData<AttrValue>: Freeze,
impl Move for Predicate
impl RefUnwindSafe for Predicate
impl Send for Predicate
impl Sync for Predicate
impl Unpin for Predicate
impl UnsafeUnpin for Predicatewhere
*const u8 is !null: UnsafeUnpin,
PhantomData<Predicate>: UnsafeUnpin,
*const Predicate is !null: UnsafeUnpin,
PhantomData<u8>: UnsafeUnpin,
PhantomData<f64>: UnsafeUnpin,
PhantomData<String>: UnsafeUnpin,
PhantomData<AttrValue>: UnsafeUnpin,
impl UnwindSafe for Predicate
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more