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
impl FilterExpressionBuilder
Sourcepub fn build(self) -> MetadataResult<FilterExpression>
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.
Sourcepub fn in_set<I, T>(self, key: &str, values: I) -> Self
pub fn in_set<I, T>(self, key: &str, values: I) -> Self
Appends a membership predicate with logical AND.
Sourcepub fn not_in_set<I, T>(self, key: &str, values: I) -> Self
pub fn not_in_set<I, T>(self, key: &str, values: I) -> Self
Appends a non-membership predicate with logical AND.
Sourcepub fn not_exists(self, key: &str) -> Self
pub fn not_exists(self, key: &str) -> Self
Appends a non-existence predicate with logical AND.
Sourcepub fn and_group<F>(self, build: F) -> Selfwhere
F: FnOnce(Self) -> Self,
pub fn and_group<F>(self, build: F) -> Selfwhere
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()?;Sourcepub fn or_group<F>(self, build: F) -> Selfwhere
F: FnOnce(Self) -> Self,
pub fn or_group<F>(self, build: F) -> Selfwhere
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));Trait Implementations§
Source§impl Clone for FilterExpressionBuilder
impl Clone for FilterExpressionBuilder
Source§fn clone(&self) -> FilterExpressionBuilder
fn clone(&self) -> FilterExpressionBuilder
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more