Skip to main content

MetadataFilter

Struct MetadataFilter 

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

An expression, its matching policy, and its resource limits.

Boolean composition belongs to FilterExpression. This type only binds an already-built expression to the options and limits used to evaluate it.

§Examples

use qubit_metadata::FilterExpression;
use qubit_metadata::Metadata;
use qubit_metadata::MetadataFilter;

let metadata = Metadata::new().with("tenant", "acme");
let expression = FilterExpression::builder()
    .eq("tenant", "acme")
    .build()?;
let filter = MetadataFilter::builder().expression(expression).build()?;
assert!(filter.matches(&metadata));

Implementations§

Source§

impl MetadataFilter

Source

pub fn all() -> Self

Creates a filter that matches every metadata object.

§Returns

A constant-true filter using default match options and library hard limits.

Source

pub fn none() -> Self

Creates a filter that matches no metadata object.

§Returns

A constant-false filter using default match options and library hard limits.

Source

pub const fn builder() -> MetadataFilterBuilder

Creates a builder for a metadata filter.

Source

pub fn deserialize_with_filter_limits<'de, D>( deserializer: D, receiver_limits: FilterLimits, ) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserializes a filter and validates a receiver-controlled AST bound.

The receiver bound is charged while the AST is being decoded. Callers must separately bound raw input bytes and any deserializer-specific resources before accepting untrusted data.

§Type Parameters
  • D - Deserializer that provides the encoded representation.
§Parameters
  • deserializer - Source of the versioned filter representation.
  • receiver_limits - Local upper bounds applied to the decoded AST.
§Returns

The decoded filter using the supplied receiver limits.

§Errors

Returns a deserialization error for malformed V1 data or an unsupported version. The underlying deserializer’s error type receives the structured filter-limit or policy failure through D::Error::custom; this generic API cannot return MetadataWireDecodeError directly.

Source

pub fn decode_json_slice(input: &[u8]) -> Result<Self, MetadataWireDecodeError>

Decodes a strict metadata-filter JSON envelope using the default wire byte and receiver AST limits.

§Parameters
  • input - Complete untrusted JSON input.
§Returns

The decoded filter.

§Errors

Returns Budget or Quantity when shared JSON traversal exceeds a configured budget, Filter when the receiver AST or filter contract exceeds its limit, UnsupportedVersion for a version mismatch, InvalidLimits for invalid metadata limits, and Syntax for empty input or lexical JSON errors. Shared decoder failures such as invalid UTF-8, unexpected top-level types, or deserialization failures return Decode. The complete unique-key JSON source tree is first materialized under the shared JSON decode budgets. The domain seed then checks receiver AST and membership limits while constructing the filter. Receiver AST or filter-contract failures return Filter; tightening FilterLimits does not stop the preceding source-tree materialization, so configure both the generic JSON budgets and domain limits.

Source

pub fn decode_json_slice_with_limits( input: &[u8], limits: MetadataLimits, receiver_filter_limits: FilterLimits, ) -> Result<Self, MetadataWireDecodeError>

Decodes a strict metadata-filter JSON envelope after validating the shared metadata limits. The complete unique-key JSON source tree is first materialized under the shared JSON decode budgets. The domain seed then checks receiver AST and membership limits while constructing the filter. Tightening receiver_filter_limits does not stop the preceding source-tree materialization, so configure both the generic JSON budgets and domain limits.

§Parameters
  • input - Complete untrusted JSON input.
  • limits - Shared JSON limits for this decoding session.
  • receiver_filter_limits - Local AST limits charged while decoding the expression tree.
§Returns

The decoded filter constrained by receiver-controlled limits.

§Errors

Returns Budget or Quantity when generic JSON traversal exceeds a configured budget, Filter when domain traversal detects an AST limit or the decoded filter violates its contract, UnsupportedVersion for a version mismatch, and InvalidLimits for invalid metadata limits. Empty input and lexical JSON errors return Syntax; shared decoder failures such as invalid UTF-8, unexpected top-level types, or other deserialization failures return Decode. Receiver AST or filter contract failures return Filter and do not retain source coordinates. Individual JSON strings and embedded value payloads remain bounded by the outer input-byte limit.

Source

pub fn to_json_vec(&self) -> Result<Vec<u8>, MetadataWireEncodeError>

Encodes this filter with the default JSON budget profile.

Uses crate::default_json_encode_limits. Decode limits do not affect output budgets. Successful filter construction does not guarantee that the encoded document fits these JSON budgets.

§Returns

Compact JSON bytes representing this filter in the V1 wire format.

§Errors

Returns crate::MetadataWireEncodeError when operand preflight, JSON budget checks, or serialization fails.

Source

pub fn to_json_vec_with_limits( &self, limits: JsonEncodeLimits, ) -> Result<Vec<u8>, MetadataWireEncodeError>

Encodes this filter with caller-provided JSON budgets.

The supplied limits apply to this encoding operation independently of the AST limits enforced during filter construction. A successfully constructed filter can still exceed these JSON budgets.

§Parameters
  • limits - Output and JSON-value budgets for this operation.
§Returns

Compact JSON bytes representing this filter in the V1 wire format.

§Errors

Returns crate::MetadataWireEncodeError when operand preflight, JSON budget checks, or serialization fails.

Source

pub fn to_json_writer<W>( &self, writer: W, ) -> Result<(), MetadataWireEncodeError>
where W: Write,

Encodes this filter to a writer with the default JSON budget profile.

The complete compact JSON document is buffered after operand preflight and budget checks, before any bytes are written to the destination. A preflight, budget, or serialization error therefore leaves the writer untouched. An I/O error during writing may leave a prefix in the writer; this method does not provide atomicity, rollback, or automatic retries. Applications are responsible for persistence and retry decisions. The default profile is returned by crate::default_json_encode_limits; decode limits do not affect the output budget.

§Type Parameters
  • W - Writer that receives the encoded representation.
§Parameters
  • writer - Destination receiving the compact JSON document.
§Returns

Returns Ok(()) after the complete document is written.

§Errors

Returns crate::MetadataWireEncodeError when operand preflight, budget checks, serialization, or destination I/O fails. Only destination I/O errors can occur after writing has started.

Source

pub fn to_json_writer_with_limits<W>( &self, writer: W, limits: JsonEncodeLimits, ) -> Result<(), MetadataWireEncodeError>
where W: Write,

Encodes this filter to a writer with caller-provided JSON budgets.

The complete compact JSON document is buffered after operand preflight and budget checks, before any bytes are written to the destination. A preflight, budget, or serialization error therefore leaves the writer untouched. An I/O error during writing may leave a prefix in the writer; this method does not provide atomicity, rollback, or automatic retries. Applications are responsible for persistence and retry decisions. The supplied JsonEncodeLimits controls encoding; decode limits do not affect the output budget.

§Type Parameters
  • W - Writer that receives the encoded representation.
§Parameters
  • writer - Destination receiving the compact JSON document.
  • limits - Output and JSON-value budgets for this operation.
§Returns

Returns Ok(()) after the complete document is written.

§Errors

Returns crate::MetadataWireEncodeError when operand preflight, budget checks, serialization, or destination I/O fails. Only destination I/O errors can occur after writing has started.

Source

pub const fn expression(&self) -> &FilterExpression

Returns the root expression.

§Returns

The expression evaluated by this filter.

Source

pub const fn options(&self) -> FilterMatchOptions

Returns the evaluation options.

§Returns

The policy used when evaluating conditions.

Source

pub const fn limits(&self) -> FilterLimits

Returns the resource limits.

§Returns

The limits validated when this filter was constructed.

Source

pub fn matches(&self, metadata: &Metadata) -> bool

Returns whether metadata satisfies this filter.

§Parameters
  • metadata - Metadata inspected by the filter.
§Returns

true when the metadata satisfies the expression and match options.

Trait Implementations§

Source§

impl Clone for MetadataFilter

Source§

fn clone(&self) -> Self

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 MetadataFilter

Source§

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

Writes the strict-policy diagnostic representation.

§Parameters
  • formatter - Formatter that receives the output.
Source§

impl<'de> Deserialize<'de> for MetadataFilter

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserializes a filter using library hard limits as receiver limits.

§Type Parameters
  • D - Deserializer that provides the encoded representation.
§Parameters
  • deserializer - Deserializer providing the filter representation.
§Returns

The reconstructed filter.

§Errors

Returns the deserializer’s error if the versioned representation is malformed or violates the filter limits.

Source§

impl PartialEq for MetadataFilter

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl Redact for MetadataFilter

Source§

fn write_redacted(&self, writer: &mut RedactionWriter<'_>)

Writes the filter through one cumulative diagnostic budget.

§Parameters
  • writer - Destination that receives the encoded or redacted output.
Source§

impl Serialize for MetadataFilter

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serializes this filter through its versioned wire representation.

§Type Parameters
  • S - Serializer that receives the encoded representation.
§Parameters
  • serializer - Serializer receiving the filter representation.
§Returns

The serializer’s representation of this filter.

§Errors

Returns the serializer’s error if conversion to the wire form or serialization fails.

Source§

impl StructuralPartialEq for MetadataFilter

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> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

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> IntoValueDefault<T> for T

Source§

fn into_value_default(self) -> T

Returns the owned value unchanged as the default.

§Returns

The input value, moved without cloning.

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.