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
impl MetadataFilter
Sourcepub fn all() -> Self
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.
Sourcepub fn none() -> Self
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.
Sourcepub const fn builder() -> MetadataFilterBuilder
pub const fn builder() -> MetadataFilterBuilder
Creates a builder for a metadata filter.
Sourcepub fn deserialize_with_filter_limits<'de, D>(
deserializer: D,
receiver_limits: FilterLimits,
) -> Result<Self, D::Error>where
D: Deserializer<'de>,
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.
Sourcepub fn decode_json_slice(input: &[u8]) -> Result<Self, MetadataWireDecodeError>
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.
Sourcepub fn decode_json_slice_with_limits(
input: &[u8],
limits: MetadataLimits,
receiver_filter_limits: FilterLimits,
) -> Result<Self, MetadataWireDecodeError>
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.
Sourcepub fn to_json_vec(&self) -> Result<Vec<u8>, MetadataWireEncodeError>
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.
Sourcepub fn to_json_vec_with_limits(
&self,
limits: JsonEncodeLimits,
) -> Result<Vec<u8>, MetadataWireEncodeError>
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.
Sourcepub fn to_json_writer<W>(
&self,
writer: W,
) -> Result<(), MetadataWireEncodeError>where
W: Write,
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.
Sourcepub fn to_json_writer_with_limits<W>(
&self,
writer: W,
limits: JsonEncodeLimits,
) -> Result<(), MetadataWireEncodeError>where
W: Write,
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.
Sourcepub const fn expression(&self) -> &FilterExpression
pub const fn expression(&self) -> &FilterExpression
Sourcepub const fn options(&self) -> FilterMatchOptions
pub const fn options(&self) -> FilterMatchOptions
Sourcepub const fn limits(&self) -> FilterLimits
pub const fn limits(&self) -> FilterLimits
Trait Implementations§
Source§impl Clone for MetadataFilter
impl Clone for MetadataFilter
Source§impl Debug for MetadataFilter
impl Debug for MetadataFilter
Source§impl<'de> Deserialize<'de> for MetadataFilter
impl<'de> Deserialize<'de> for MetadataFilter
Source§fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>where
D: Deserializer<'de>,
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
impl PartialEq for MetadataFilter
Source§impl Redact for MetadataFilter
impl Redact for MetadataFilter
Source§fn write_redacted(&self, writer: &mut RedactionWriter<'_>)
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
impl Serialize for MetadataFilter
Source§fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>where
S: Serializer,
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.