Skip to main content

Predicate

Enum Predicate 

Source
#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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.

Fields

§field: String

The field.

§op: Compare

The comparison.

§value: f64

The value, finite.

§

NumberIn

A number field equals one of the values.

Fields

§field: String

The field.

§values: Vec<f64>

The values, at least one, all finite.

§

Between

A number field is between low and high, both included.

Fields

§field: String

The field.

§low: f64

The lower bound, finite.

§high: f64

The upper bound, finite and not below low.

§

Text

A string field compared with a value.

Fields

§field: String

The field.

§op: TextCompare

The comparison.

§value: String

The value.

§

TextIn

A string field equals one of the values.

Fields

§field: String

The field.

§values: Vec<String>

The values, at least one.

§

Contains

A set field holds the element.

Fields

§field: String

The field.

§value: AttrValue

The element. Its kind must be the set’s element type.

§

ContainsAny

A set field holds at least one of the elements.

Fields

§field: String

The field.

§values: Vec<AttrValue>

The elements, at least one.

§

ContainsAll

A set field holds every one of the elements.

Fields

§field: String

The field.

§values: Vec<AttrValue>

The elements, at least one.

§

IsEmpty(String)

A set field is present and has no elements. A null field is not empty.

Implementations§

Source§

impl Predicate

Source

pub fn is_true(field: impl Into<String>) -> Self

A bool field is true.

Source

pub fn is_false(field: impl Into<String>) -> Self

A bool field is false.

Source

pub fn number(field: impl Into<String>, op: Compare, value: f64) -> Self

A number field compared with value.

Source

pub fn text( field: impl Into<String>, op: TextCompare, value: impl Into<String>, ) -> Self

A string field compared with value.

Source

pub fn and(items: Vec<Predicate>) -> Self

Every condition holds.

Source

pub fn or(items: Vec<Predicate>) -> Self

At least one condition holds.

Source

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 Clone for Predicate

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Predicate

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<'de> Deserialize<'de> for Predicate

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl PartialEq for Predicate

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for Predicate

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for Predicate

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.