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, MetadataError::FilterLimitExceeded for oversized trees, or
MetadataError::InvalidFilterOperand for unset operands or operands
that cannot be represented by the V1 wire format, including non-finite
floating-point values. Chained construction retains the first error
and returns it from this method.
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
Sourcepub fn exists(self, key: &str) -> Self
pub fn exists(self, key: &str) -> Self
Appends an existence predicate with logical AND.
§Parameters
key- Metadata key used by the condition.
Sourcepub fn not_exists(self, key: &str) -> Self
pub fn not_exists(self, key: &str) -> Self
Appends a non-existence predicate with logical AND.
§Parameters
key- Metadata key used by the condition.
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.
§Type Parameters
F- Callback that visits operands or constructs a nested group.
§Parameters
build- Callback that constructs the nested group.
§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.
§Type Parameters
F- Callback that visits operands or constructs a nested group.
§Parameters
build- Callback that constructs the nested group.
§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));