Skip to main content

MetadataSchema

Struct MetadataSchema 

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

Schema for metadata fields.

A schema declares valid keys, their concrete DataType, and whether they are required. It can validate actual Metadata values and validate that a crate::MetadataFilter references known fields with compatible operators.

§Examples

use qubit_datatype::DataType;
use qubit_metadata::Metadata;
use qubit_metadata::MetadataSchema;

let metadata = Metadata::new().with("tenant", "acme");
let schema = MetadataSchema::builder()
    .required("tenant", DataType::String)
    .build()?;
schema.validate(&metadata)?;

Implementations§

Source§

impl MetadataSchema

Source

pub fn validate_filter( &self, filter: &MetadataFilter, ) -> MetadataValidationResult<()>

Validates a metadata filter against this schema.

§Parameters
  • filter - Filter to validate.
§Returns

Ok(()) when every condition is compatible with this schema.

§Errors

Returns an aggregate error containing every unknown field, invalid range operator, and incompatible filter value discovered during this validation pass. Unknown filter fields are accepted when the schema’s UnknownFilterFieldPolicy is UnknownFilterFieldPolicy::AllowUnchecked.

Source§

impl MetadataSchema

Source

pub fn builder() -> MetadataSchemaBuilder

Creates a schema builder.

§Returns

An empty schema builder using the default unknown-field policy.

Source

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

Decodes a strict metadata-schema JSON envelope using the metadata profile.

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

The decoded metadata schema.

§Errors

Returns Budget or Quantity when shared JSON traversal exceeds a configured limit, Domain for schema field/key limits, 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 deserialization failures return Decode.

Source

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

Decodes a strict metadata-schema JSON envelope after applying limits.

§Parameters
  • input - Complete untrusted JSON input.
  • limits - Shared JSON limits for this decoding session.
§Returns

The decoded metadata schema.

§Errors

Returns Budget or Quantity when shared JSON traversal exceeds a configured limit, Domain for schema field/key limits, 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 deserialization failures return Decode.

Source

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

Encodes this schema with the default JSON budget profile (crate::default_json_encode_limits).

§Errors

Returns crate::MetadataWireEncodeError::Domain when the schema exceeds a V1 wire limit, before checking JSON output budgets. Returns crate::MetadataWireEncodeError when encoding exceeds a default JSON budget or serialization fails.

§Returns

The compact JSON bytes representing this schema.

Source

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

Encodes this schema with caller-provided JSON budgets.

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

Returns crate::MetadataWireEncodeError when a schema field count or key exceeds the V1 wire limit, encoding exceeds a JSON budget, or serialization fails. Schema wire-limit errors are reported as Domain(MetadataError::WireLimitExceeded { .. }) before JSON budgets.

§Returns

The compact JSON bytes representing this schema.

Source

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

Encodes this schema to a writer with the default JSON budget profile (crate::default_json_encode_limits).

The complete compact JSON document is buffered and validated before the first write to writer. A budget or serialization failure leaves the destination untouched by this operation. A destination I/O error may leave a written prefix; this method does not provide atomic writes or rollback. Applications own persistence and retry semantics. Decode limits do not affect output budgets; use Self::to_json_writer_with_limits to provide explicit output budgets.

§Returns

Ok(()) after the buffered document is written successfully.

§Type Parameters
  • W - Writer receiving the encoded JSON document.
§Parameters
  • writer - Destination receiving the complete compact JSON document.
§Errors

Returns crate::MetadataWireEncodeError when a schema field count or key exceeds the V1 wire limit, a JSON budget or serialization failure occurs before writing, or the destination writer rejects bytes. Schema wire-limit errors are reported as Domain(MetadataError::WireLimitExceeded { .. }) before JSON budgets.

Source

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

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

§Parameters
  • writer - Destination receiving the complete compact JSON document.
  • limits - Explicit output and JSON-value budgets for this operation.

The complete compact JSON document is buffered and validated before the first write to writer. A budget or serialization failure leaves the destination untouched by this operation. A destination I/O error may leave a written prefix; this method does not provide atomic writes or rollback. Applications own persistence and retry semantics. Output budgets come only from the explicitly supplied limits; decode limits do not affect them.

§Returns

Ok(()) after the buffered document is written successfully.

§Errors

Returns crate::MetadataWireEncodeError::Domain when the schema exceeds a V1 wire limit. Wire-contract validation runs before JSON output budgets. Budget or serialization failures occur before any destination write; destination I/O errors may leave a written prefix.

§Type Parameters
  • W - Writer receiving the encoded JSON document.
Source

pub fn field(&self, key: &str) -> Option<&MetadataField>

Returns the field definition for key.

§Parameters
  • key - Metadata key to look up.
§Returns

Some field definition for a declared key; otherwise, None.

Source

pub fn field_type(&self, key: &str) -> Option<DataType>

Returns the declared data type for key.

§Parameters
  • key - Metadata key to look up.
§Returns

Some declared data type for a known key; otherwise, None.

Source

pub fn unknown_metadata_field_policy(&self) -> UnknownMetadataFieldPolicy

Returns the policy for undeclared metadata fields.

§Returns

The policy applied to undeclared metadata keys.

Source

pub fn unknown_filter_field_policy(&self) -> UnknownFilterFieldPolicy

Returns the policy for undeclared filter fields.

§Returns

The policy applied to filter keys not declared in this schema.

Source

pub fn fields(&self) -> impl Iterator<Item = (&str, &MetadataField)>

Returns an iterator over schema fields in key-sorted order.

§Returns

An iterator yielding key and field-definition pairs.

Source

pub fn validate(&self, meta: &Metadata) -> MetadataValidationResult<()>

Validates a metadata object against this schema.

§Parameters
  • meta - Metadata object to validate.
§Returns

Ok(()) when every entry satisfies the schema.

§Errors

Returns an aggregate error containing every required-field, declared-type, and unknown-field issue discovered during this validation pass.

Source

pub fn validate_wire_contract(&self) -> MetadataResult<()>

Validates that this schema fits the strict V1 wire contract.

This preflight checks the same field-count and key-byte limits enforced by Serialize::serialize, allowing callers to reject invalid schemas before crossing a persistence or network boundary.

§Returns

Ok(()) when every field can satisfy the schema map limits.

§Errors

Returns MetadataError::WireLimitExceeded when the field count or a field key exceeds the strict V1 limit.

Trait Implementations§

Source§

impl Clone for MetadataSchema

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 MetadataSchema

Source§

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

Writes the strict-policy diagnostic representation.

§Parameters
  • formatter - Formatter receiving the redacted representation.
Source§

impl Default for MetadataSchema

Source§

fn default() -> Self

Creates an empty schema that rejects undeclared metadata and filter fields.

Source§

impl<'de> Deserialize<'de> for MetadataSchema

Source§

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

Deserializes only the strict v1 schema envelope.

§Type Parameters
  • D - Deserializer providing the schema envelope.
§Parameters
  • deserializer - Source of the serialized schema.
§Returns

The schema decoded from the strict v1 envelope.

§Errors

Returns the deserializer’s error when the envelope is malformed or its version is unsupported.

Source§

impl Eq for MetadataSchema

Source§

impl PartialEq for MetadataSchema

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 MetadataSchema

Source§

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

Writes schema fields through one cumulative diagnostic budget.

§Parameters
  • writer - Redaction writer receiving the schema representation.
Source§

impl Serialize for MetadataSchema

Source§

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

Serializes this schema as its strict v1 envelope.

§Type Parameters
  • S - Serializer receiving the schema envelope.
§Parameters
  • serializer - Destination serializer for the schema.
§Returns

The serializer’s success value after encoding the strict v1 envelope.

§Errors

Returns the serializer’s error when the schema exceeds wire limits or serialization fails.

Source§

impl StructuralPartialEq for MetadataSchema

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.