Skip to main content

Builder

Struct Builder 

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

Filter builder.

This data type uses a Slab to store conditions efficiently, which makes it possible to keep indices stable when adding or removing expressions. It allows users to modify a Filter dynamically, and rebuild it on-the-fly after all modifications were made.

Implementations§

Source§

impl Builder

Source

pub fn insert<T>(&mut self, expr: T) -> usize
where T: Into<Expression>,

Inserts an expression into the filter and returns its index.

This method adds an Expression to the filter builder, and returns the index of the inserted condition, which can be used to remove it.

Note that the expression is immediately converted into a [Condition] for performance reasons, which means it cannot be recovered. If we’d store expressions directly, removing or inserting new expressions into the filter would mandate recompilation of all expressions.

§Examples
use zrx_id::expression::Filter;
use zrx_id::{selector, Expression};

// Create filter builder and insert expression
let mut builder = Filter::builder();
builder.insert(Expression::any(|expr| {
    expr.with(selector!(location = "**/*.jpg")?)?
        .with(selector!(location = "**/*.png")?)
})?);
Source

pub fn remove(&mut self, index: usize)

Removes an expression from the filter.

§Examples
use zrx_id::expression::Filter;
use zrx_id::{selector, Expression};

// Create filter builder and insert expression
let mut builder = Filter::builder();
builder.insert(Expression::any(|expr| {
    expr.with(selector!(location = "**/*.jpg")?)?
        .with(selector!(location = "**/*.png")?)
})?);

// Remove expression
builder.remove(0);
Source

pub fn build(self) -> Result<Filter, Error>

Builds the filter.

§Errors

Returns Error::Matcher if the underlying matcher can’t be built.

§Examples
use zrx_id::expression::Filter;
use zrx_id::{selector, Expression};

// Create filter builder and insert expression
let mut builder = Filter::builder();
builder.insert(Expression::any(|expr| {
    expr.with(selector!(location = "**/*.jpg")?)?
        .with(selector!(location = "**/*.png")?)
})?);

// Create filter from builder
let filter = builder.build()?;
Source§

impl Builder

Source

pub fn len(&self) -> usize

Returns the number of expressions.

Source

pub fn is_empty(&self) -> bool

Returns whether there are any expressions.

Trait Implementations§

Source§

impl Debug for Builder

Source§

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

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

impl Default for Builder

Source§

fn default() -> Builder

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

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> Arguments for T
where T: Send + Sync + 'static,

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> 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> 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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.