Skip to main content

Predicate

Enum Predicate 

Source
pub enum Predicate {
Show 17 variants Exists { key: TagKey, }, Equals { key: TagKey, value: String, }, NumericAtLeast { key: TagKey, threshold: f64, }, NumericAtMost { key: TagKey, threshold: f64, }, NumericInRange { key: TagKey, min: f64, max: f64, }, SemverAtLeast { key: TagKey, version: String, }, SemverAtMost { key: TagKey, version: String, }, SemverCompatible { key: TagKey, version: String, }, StringPrefix { key: TagKey, prefix: String, }, StringMatches { key: TagKey, pattern: String, }, MetadataExists { key: String, }, MetadataEquals { key: String, value: String, }, MetadataMatches { key: String, pattern: String, }, MetadataNumericAtLeast { key: String, threshold: f64, }, And(Vec<Predicate>), Or(Vec<Predicate>), Not(Box<Predicate>),
}
Expand description

AST for capability queries. Pure data — clones, equality, and serde round-trip are the basis of cross-binding wire format.

See module docs for the variant taxonomy.

Variants§

§

Exists

Tag with this (axis, key) is present (regardless of value).

Fields

§key: TagKey

Tag key to probe.

§

Equals

Tag’s value matches exactly. Presence-only tags don’t match (use Predicate::Exists for that).

Fields

§key: TagKey

Tag key.

§value: String

Required value (string-equality).

§

NumericAtLeast

Tag’s value parses to f64 and is >= threshold.

Fields

§key: TagKey

Tag key.

§threshold: f64

Inclusive lower bound.

§

NumericAtMost

Tag’s value parses to f64 and is <= threshold.

Fields

§key: TagKey

Tag key.

§threshold: f64

Inclusive upper bound.

§

NumericInRange

Tag’s value parses to f64 and lies in [min, max] inclusive.

Fields

§key: TagKey

Tag key.

§min: f64

Inclusive lower bound.

§max: f64

Inclusive upper bound.

§

SemverAtLeast

Tag’s value parses to MAJOR.MINOR.PATCH and is >= version.

Fields

§key: TagKey

Tag key.

§version: String

Reference version.

§

SemverAtMost

Tag’s value parses to MAJOR.MINOR.PATCH and is <= version.

Fields

§key: TagKey

Tag key.

§version: String

Reference version.

§

SemverCompatible

Tag’s value parses to MAJOR.MINOR.PATCH and is in the same compatibility band: same major for >= 1.0.0, same minor for 0.x.y. Mirrors the standard semver caret-compatibility rule.

Fields

§key: TagKey

Tag key.

§version: String

Reference version.

§

StringPrefix

Tag’s value starts with prefix.

Fields

§key: TagKey

Tag key.

§prefix: String

Prefix to match.

§

StringMatches

Tag’s value contains pattern as a substring. Phase E will upgrade to regex behind the regex feature gate; semantics today are substring-only.

Fields

§key: TagKey

Tag key.

§pattern: String

Substring pattern.

§

MetadataExists

Metadata key is present.

Fields

§key: String

Metadata key.

§

MetadataEquals

Metadata value matches exactly.

Fields

§key: String

Metadata key.

§value: String

Required value (string-equality).

§

MetadataMatches

Metadata value contains pattern as a substring (same substring-only semantics as Predicate::StringMatches).

Fields

§key: String

Metadata key.

§pattern: String

Substring pattern.

§

MetadataNumericAtLeast

Metadata value parses to f64 and is >= threshold.

Fields

§key: String

Metadata key.

§threshold: f64

Inclusive lower bound.

§

And(Vec<Predicate>)

Conjunction. Empty Vec evaluates to true (vacuous match — matches the standard math/logic convention; pin in tests).

§

Or(Vec<Predicate>)

Disjunction. Empty Vec evaluates to false (vacuous miss).

§

Not(Box<Predicate>)

Negation.

Implementations§

Source§

impl Predicate

Source

pub fn to_wire(&self) -> PredicateWire

Convert to the flat wire format. Post-order serialization: leaves land first, the root has the highest index.

Output is byte-stable across calls — two to_wire()s on equal predicates produce identical PredicateWire values (and identical bytes through any serde encoder).

Source§

impl Predicate

Source

pub fn matches_capability_set(&self, caps: &CapabilitySet) -> bool

True if this predicate evaluates to true against the given super::capability::CapabilitySet’s tags + metadata.

Materializes caps.tags (a HashSet<Tag>) as a Vec<Tag> for the slice-based EvalContext. The cost is a single allocation per call; for hot loops over many capability sets, callers may prefer to materialize tags once and invoke Self::evaluate directly.

Source§

impl Predicate

Source

pub fn exists(key: TagKey) -> Self

Build Predicate::Exists from a TagKey.

Source

pub fn equals(key: TagKey, value: impl Into<String>) -> Self

Build Predicate::Equals from a key + value.

Source

pub fn numeric_at_least(key: TagKey, threshold: f64) -> Self

Source

pub fn numeric_at_most(key: TagKey, threshold: f64) -> Self

Source

pub fn numeric_in_range(key: TagKey, min: f64, max: f64) -> Self

Source

pub fn semver_at_least(key: TagKey, version: impl Into<String>) -> Self

Source

pub fn semver_at_most(key: TagKey, version: impl Into<String>) -> Self

Source

pub fn semver_compatible(key: TagKey, version: impl Into<String>) -> Self

Source

pub fn string_prefix(key: TagKey, prefix: impl Into<String>) -> Self

Source

pub fn string_matches(key: TagKey, pattern: impl Into<String>) -> Self

Source

pub fn metadata_exists(key: impl Into<String>) -> Self

Source

pub fn metadata_equals(key: impl Into<String>, value: impl Into<String>) -> Self

Source

pub fn metadata_matches( key: impl Into<String>, pattern: impl Into<String>, ) -> Self

Source

pub fn metadata_numeric_at_least(key: impl Into<String>, threshold: f64) -> Self

Source

pub fn and(clauses: Vec<Predicate>) -> Self

Build Predicate::And from a Vec of clauses.

Source

pub fn or(clauses: Vec<Predicate>) -> Self

Build Predicate::Or from a Vec of clauses.

Source

pub fn not(inner: Predicate) -> Self

Build Predicate::Not wrapping a single clause.

Named not to match and / or as a constructor — not an Op<Output = Predicate> impl. Implementing std::ops::Not would force callers to depend on Predicate: Not for the ! operator, which requires Predicate: Sized + Not<Output = ?> boilerplate without any expressivity gain over the explicit constructor.

Source§

impl Predicate

Source

pub fn evaluate(&self, ctx: &EvalContext<'_>) -> bool

Evaluate against (tags, metadata). Pure function.

Phase 4 of CAPABILITY_ENHANCEMENTS_PLAN.md: at every And / Or node, children are evaluated in cost-ascending order so cheap+selective clauses short-circuit first. The reordering is a pure local optimization — semantics are identical to Self::evaluate_unplanned. Pinned by the planned_evaluate_matches_unplanned_* property tests.

Numeric / semver parse failures yield false (a malformed tag value shouldn’t fault a federated query).

Source

pub fn evaluate_unplanned(&self, ctx: &EvalContext<'_>) -> bool

Evaluate without the planner — children of And / Or run in declaration order.

Phase 4 escape hatch for benchmarking and the planner- equivalence property tests. Production callers should use Self::evaluate; this is a diagnostic surface only.

Source

pub fn evaluate_with_index<P: CardinalityProvider>( &self, ctx: &EvalContext<'_>, index: &P, ) -> bool

Evaluate against ctx, using index’s per-key cardinality data to refine the planner’s clause ordering at every And / Or node.

Phase 4 follow-on of CAPABILITY_ENHANCEMENTS_PLAN.md. Produces the same boolean result as Self::evaluate_unplanned for any (ast, ctx); the index only changes execution order, not semantics. Pinned in the index_planner_evaluate_matches_unplanned_* property tests.

When the index is available, prefer this entry point over Self::evaluate (static-cost planner) — cardinality data catches selective clauses the static planner misses (e.g., a MetadataEquals happens to be the cheapest leaf statically, but a high-cardinality Equals on an axis tag is even more selective in this index’s data).

When the index is unavailable or unhelpful (zero-cardinality for every key — empty index), this falls back to behavior equivalent to Self::evaluate.

Source§

impl Predicate

Source

pub fn evaluate_with_trace(&self, ctx: &EvalContext<'_>) -> (bool, ClauseTrace)

Evaluate against ctx, also producing a tree of per-clause traces.

The result equals self.evaluate(ctx); this entry point adds the ClauseTrace tree as a side channel for debug inspection. Composite clauses retain the planner’s short-circuit behavior — descendants that didn’t run aren’t in the trace.

Phase 6 of CAPABILITY_ENHANCEMENTS_PLAN.md. Opt-in only; production callers use Predicate::evaluate.

Trait Implementations§

Source§

impl Clone for Predicate

Source§

fn clone(&self) -> Predicate

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Predicate

Source§

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

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

impl PartialEq for Predicate

Source§

fn eq(&self, other: &Predicate) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Predicate

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more