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 a structured budget error or InvalidJson for malformed strict schema input.

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 a structured budget error, Domain for field/key limits, UnsupportedVersion for version mismatches, or redacted JSON errors for syntax and other strict schema-envelope failures.

Source

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

Encodes this schema with the default JSON budget profile.

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 encoding exceeds a budget or serialization fails.

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.

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 compact JSON document.
  • limits - Output and JSON-value budgets for this operation.
§Errors

Returns crate::MetadataWireEncodeError when encoding exceeds a budget, serialization fails, or writer rejects the output.

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) -> MetadataSchema

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, f: &mut Formatter<'_>) -> Result

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

impl Default for MetadataSchema

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
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.

Source§

impl Eq for MetadataSchema

Source§

impl PartialEq for MetadataSchema

Source§

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

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

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

Inequality operator !=. Read more
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.

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

Converts this argument into the default value. Read more
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.