pub struct Expression { /* private fields */ }Expand description
Expression.
Expressions allow to build trees of Id and Selector instances
combined with logical operators, enabling complex matching and filtering.
The following operators are supported:
Expression::any: LogicalOR- any operand must match.Expression::all: LogicalAND- all operands must match.Expression::not: LogicalNOT- no operand must match.
§Examples
use zrx_id::{selector, Expression};
// Create expression
let expr = Expression::all(|expr| {
expr.with(selector!(location = "**/*.md")?)?
.with(Expression::not(|expr| {
expr.with(selector!(provider = "file")?)
})
)
})?;Implementations§
Source§impl Expression
impl Expression
Sourcepub fn any<F>(f: F) -> Result<Self>
pub fn any<F>(f: F) -> Result<Self>
Creates an expression for which any operand must match.
§Errors
Returns Error::Id if any of the operands are invalid.
§Examples
use zrx_id::{selector, Expression};
// Create expression
let expr = Expression::any(|expr| {
expr.with(selector!(location = "**/*.jpg")?)?
.with(selector!(location = "**/*.png")?)
})?;Sourcepub fn all<F>(f: F) -> Result<Self>
pub fn all<F>(f: F) -> Result<Self>
Creates an expression for which all operands must match.
§Errors
Returns Error::Id if any of the operands are invalid.
§Examples
use zrx_id::{selector, Expression};
// Create expression
let expr = Expression::all(|expr| {
expr.with(selector!(location = "**/*.md")?)?
.with(selector!(provider = "file")?)
})?;Sourcepub fn not<F>(f: F) -> Result<Self>
pub fn not<F>(f: F) -> Result<Self>
Creates an expression for which no operand must match.
§Errors
Returns Error::Id if any of the operands are invalid.
§Examples
use zrx_id::{selector, Expression};
// Create expression
let expr = Expression::all(|expr| {
expr.with(selector!(location = "**/*.md")?)?
.with(Expression::not(|expr| {
expr.with(selector!(provider = "file")?)
})
)
})?;Source§impl Expression
impl Expression
Trait Implementations§
Source§impl Clone for Expression
impl Clone for Expression
Source§fn clone(&self) -> Expression
fn clone(&self) -> Expression
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for Expression
impl Debug for Expression
Source§impl Default for Expression
impl Default for Expression
Source§fn default() -> Self
fn default() -> Self
Creates an expression that matches everything.
While it may seem counterintuitive to have the default expression match everything, it is designed this way to align with the concept of vacuous truth in logic. An expression with no operands is considered to be true, as there are no conditions to violate it.
In our implementation, we use an empty expression with a logical NOT
operator to represent this concept, to be distinguishable as a marker.
§Examples
use zrx_id::Expression;
// Create empty expression
let expr = Expression::default();
assert!(expr.is_empty());Source§impl From<Expression> for Operand
impl From<Expression> for Operand
Source§fn from(expr: Expression) -> Self
fn from(expr: Expression) -> Self
Creates an operand from an expression.
Source§impl<T> From<T> for Expression
impl<T> From<T> for Expression
Source§impl IntoIterator for Expression
impl IntoIterator for Expression
Source§fn into_iter(self) -> Self::IntoIter
fn into_iter(self) -> Self::IntoIter
Creates a consuming iterator over the expression.
§Examples
use zrx_id::{selector, Expression};
// Create expression
let expr = Expression::any(|expr| {
expr.with(selector!(location = "**/*.jpg")?)?
.with(selector!(location = "**/*.png")?)
})?;
// Create iterator over expression
for operand in expr {
println!("{operand:?}");
}Source§type IntoIter = IntoIter<<Expression as IntoIterator>::Item>
type IntoIter = IntoIter<<Expression as IntoIterator>::Item>
Source§impl PartialEq for Expression
impl PartialEq for Expression
Source§impl ToSpecificity for Expression
impl ToSpecificity for Expression
Source§fn to_specificity(&self) -> Specificity
fn to_specificity(&self) -> Specificity
Computes the specificity of the expression.
§Examples
use zrx_id::specificity::ToSpecificity;
use zrx_id::{selector, Expression};
// Create expression and compute specificity
let expr = Expression::any(|expr| {
expr.with(selector!(location = "**/*.jpg")?)?
.with(selector!(location = "**/*.png")?)
})?;
assert_eq!(expr.to_specificity(), (0, 1, 1, 4).into());impl Eq for Expression
impl StructuralPartialEq for Expression
Auto Trait Implementations§
impl Freeze for Expression
impl RefUnwindSafe for Expression
impl Send for Expression
impl Sync for Expression
impl Unpin for Expression
impl UnsafeUnpin for Expression
impl UnwindSafe for Expression
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,
Source§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<K, V> TryAsStorage<K> for V
impl<K, V> TryAsStorage<K> for V
Source§fn try_as_storage(
item: &(dyn Any + 'static),
) -> Result<<V as TryAsStorage<K>>::Target<'_>, Error>
fn try_as_storage( item: &(dyn Any + 'static), ) -> Result<<V as TryAsStorage<K>>::Target<'_>, Error>
Attempts to convert into a storage reference.
§Errors
The following errors might be returned:
Error::Downcast: Item cannot be downcast.
§Examples
use std::any::Any;
use zrx_storage::convert::TryAsStorage;
use zrx_storage::Storage;
// Create storage and initial state
let mut storage = Storage::default();
storage.insert("key", 42);
// Obtain type-erased reference
let item: &dyn Any = &storage;
// Obtain storage reference
let storage = <i32>::try_as_storage(item)?;Source§impl<K, V> TryAsStorageMut<K> for V
impl<K, V> TryAsStorageMut<K> for V
Source§fn try_as_storage_mut(
item: &mut (dyn Any + 'static),
) -> Result<<V as TryAsStorageMut<K>>::Target<'_>, Error>
fn try_as_storage_mut( item: &mut (dyn Any + 'static), ) -> Result<<V as TryAsStorageMut<K>>::Target<'_>, Error>
Attempts to convert into a mutable storage reference.
§Errors
The following errors might be returned:
Error::Downcast: Item cannot be downcast.
§Examples
use std::any::Any;
use zrx_storage::convert::TryAsStorageMut;
use zrx_storage::Storage;
// Create storage and initial state
let mut storage = Storage::default();
storage.insert("key", 42);
// Obtain mutable type-erased reference
let item: &mut dyn Any = &mut storage;
// Obtain mutable storage reference
let storage = <i32>::try_as_storage_mut(item)?;