Skip to main content

Filter

Struct Filter 

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

Filter.

Filters efficiently match identifiers against a set of expressions, which are composed of conditions and logical operators, and compiled into a set of optimized instructions. This makes it possible to evaluate arbitrarily complex logical expressions against identifiers extremely fast.

Each Filter manages a Matcher, used to identify matching terms in expressions in nanoseconds, and a set of conditions built from expressions, which are checked for satisfiability by using a bitwise stack-based virtual machine with an optimized set of instructions. Thus, the Matcher can be thought of as the first stage, eliminating non-matching expressions, while the condition set is the second stage, which checks whether the remaining expressions are actually satisfied by the identifier.

§Examples

use zrx_id::{selector, Expression, Filter, Id};

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

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

// Create identifier and obtain candidate expressions
let id: Id = "zri:file:::docs:index.md:".parse()?;
for index in filter.candidates(&id)? {
    println!("{index:?}");
}

Implementations§

Source§

impl Filter

Source

pub fn builder() -> Builder

Creates a filter builder.

§Examples
use zrx_id::Filter;

// Create filter builder
let mut builder = Filter::builder();
Source

pub fn into_builder(self) -> Builder

Creates a filter builder from the filter.

This method allows to modify an existing Filter by converting it back into a filter builder to insert or remove expressions.

§Examples
use zrx_id::Filter;

// Create filter
let filter = Filter::default();

// Create filter builder
let mut builder = filter.into_builder();
Source§

impl Filter

Source

pub fn candidates<T>(&self, id: &T) -> Result<Candidates<'_>>
where T: TryToId,

Returns the indices of expressions that match the identifier.

This method compares expressions part of the filter against the given identifier, and returns an iterator over the indices of the expressions that match. Note that the order of the returned indices corresponds to the order in which the expressions were added to the filter.

§Errors

Returns Error::Matcher if the identifier is invalid.

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

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

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

// Create identifier and obtain candidate expressions
let id: Id = "zri:file:::docs:index.md:".parse()?;
for index in filter.candidates(&id)? {
    println!("{index:?}");
}
Source§

impl Filter

Source

pub fn terms(&self) -> Terms<'_>

Creates an iterator over the terms.

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

// 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()?;

// Create iterator over terms
for term in filter.terms() {
    println!("{term:?}");
}
Source§

impl Filter

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 Filter

Source§

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

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

impl Default for Filter

Source§

fn default() -> Filter

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> 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.