Skip to main content

FilterExpressionBuilder

Struct FilterExpressionBuilder 

Source
pub struct FilterExpressionBuilder { /* private fields */ }
Expand description

Fluent builder for a non-empty FilterExpression.

Predicates without an explicit connector are joined by logical AND. Construction stops at the first invalid operand or resource limit. Later operands are not converted, iterators are not consumed, and group callbacks are not invoked. Argument expressions themselves are still evaluated by Rust.

§Examples

use qubit_metadata::FilterExpressionBuilder;

let expression = FilterExpressionBuilder::default()
    .eq("tenant", "acme")
    .build()?;
assert!(matches!(expression.view(), qubit_metadata::FilterExpressionView::Condition(_)));

Implementations§

Source§

impl FilterExpressionBuilder

Source

pub fn build(self) -> MetadataResult<FilterExpression>

Builds the assembled expression.

§Errors

Returns MetadataError::InvalidFilterExpression for empty or invalid groups, or MetadataError::FilterLimitExceeded for oversized trees.

Source

pub fn eq<T>(self, key: &str, value: T) -> Self
where T: Into<Value>,

Appends key == value with logical AND.

Source

pub fn ne<T>(self, key: &str, value: T) -> Self
where T: Into<Value>,

Appends key != value with logical AND.

Source

pub fn lt<T>(self, key: &str, value: T) -> Self
where T: Into<Value>,

Appends key < value with logical AND.

Source

pub fn le<T>(self, key: &str, value: T) -> Self
where T: Into<Value>,

Appends key <= value with logical AND.

Source

pub fn gt<T>(self, key: &str, value: T) -> Self
where T: Into<Value>,

Appends key > value with logical AND.

Source

pub fn ge<T>(self, key: &str, value: T) -> Self
where T: Into<Value>,

Appends key >= value with logical AND.

Source

pub fn in_set<I, T>(self, key: &str, values: I) -> Self
where I: IntoIterator<Item = T>, T: Into<Value>,

Appends a membership predicate with logical AND.

Source

pub fn not_in_set<I, T>(self, key: &str, values: I) -> Self
where I: IntoIterator<Item = T>, T: Into<Value>,

Appends a non-membership predicate with logical AND.

Source

pub fn exists(self, key: &str) -> Self

Appends an existence predicate with logical AND.

Source

pub fn not_exists(self, key: &str) -> Self

Appends a non-existence predicate with logical AND.

Source

pub fn and_group<F>(self, build: F) -> Self
where F: FnOnce(Self) -> Self,

Appends a grouped expression with logical AND.

§Examples
use qubit_metadata::FilterExpression;

let expression = FilterExpression::builder()
    .eq("tenant", "acme")
    .and_group(|group| group.exists("region").ne("region", "blocked"))
    .build()?;
Source

pub fn or_group<F>(self, build: F) -> Self
where F: FnOnce(Self) -> Self,

Appends a grouped expression with logical OR.

§Examples
use qubit_metadata::{
    FilterExpression,
    Metadata,
    MetadataFilter,
};

let expression = FilterExpression::builder()
    .eq("tenant", "acme")
    .or_group(|group| {
        group
            .eq("priority", 1_i64)
            .or_group(|alternative| alternative.eq("priority", 2_i64))
    })
    .build()?;
let filter = MetadataFilter::builder()
    .expression(expression)
    .build()?;
let metadata = Metadata::new()
    .with("tenant", "other")
    .with("priority", 2_i64);

assert!(filter.matches(&metadata));
Source

pub fn not(self) -> Self

Negates the expression built so far.

§Examples
use qubit_metadata::FilterExpression;

let expression = FilterExpression::builder()
    .eq("state", "deleted")
    .not()
    .build()?;

Trait Implementations§

Source§

impl Clone for FilterExpressionBuilder

Source§

fn clone(&self) -> FilterExpressionBuilder

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 FilterExpressionBuilder

Source§

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

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

impl Default for FilterExpressionBuilder

Source§

fn default() -> FilterExpressionBuilder

Returns the “default value” for a type. Read more
Source§

impl PartialEq for FilterExpressionBuilder

Source§

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

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for FilterExpressionBuilder

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> 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> IntoValueDefault<T> for T

Source§

fn into_value_default(self) -> T

Converts this argument into the default value. 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.