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
impl MetadataSchema
Sourcepub fn validate_filter(
&self,
filter: &MetadataFilter,
) -> MetadataValidationResult<()>
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
impl MetadataSchema
Sourcepub fn builder() -> MetadataSchemaBuilder
pub fn builder() -> MetadataSchemaBuilder
Sourcepub fn decode_json_slice(input: &[u8]) -> Result<Self, MetadataWireDecodeError>
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.
Sourcepub fn decode_json_slice_with_limits(
input: &[u8],
limits: MetadataLimits,
) -> Result<Self, MetadataWireDecodeError>
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.
Sourcepub fn to_json_vec(&self) -> Result<Vec<u8>, MetadataWireEncodeError>
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.
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 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.
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 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.
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 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.
Sourcepub fn field(&self, key: &str) -> Option<&MetadataField>
pub fn field(&self, key: &str) -> Option<&MetadataField>
Sourcepub fn field_type(&self, key: &str) -> Option<DataType>
pub fn field_type(&self, key: &str) -> Option<DataType>
Sourcepub fn unknown_metadata_field_policy(&self) -> UnknownMetadataFieldPolicy
pub fn unknown_metadata_field_policy(&self) -> UnknownMetadataFieldPolicy
Returns the policy for undeclared metadata fields.
§Returns
The policy applied to undeclared metadata keys.
Sourcepub fn unknown_filter_field_policy(&self) -> UnknownFilterFieldPolicy
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.
Sourcepub fn fields(&self) -> impl Iterator<Item = (&str, &MetadataField)>
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.
Sourcepub fn validate(&self, meta: &Metadata) -> MetadataValidationResult<()>
pub fn validate(&self, meta: &Metadata) -> MetadataValidationResult<()>
Sourcepub fn validate_wire_contract(&self) -> MetadataResult<()>
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
impl Clone for MetadataSchema
Source§impl Debug for MetadataSchema
impl Debug for MetadataSchema
Source§impl Default for MetadataSchema
impl Default for MetadataSchema
Source§impl<'de> Deserialize<'de> for MetadataSchema
impl<'de> Deserialize<'de> for MetadataSchema
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 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.
impl Eq for MetadataSchema
Source§impl PartialEq for MetadataSchema
impl PartialEq for MetadataSchema
Source§impl Redact for MetadataSchema
impl Redact for MetadataSchema
Source§fn write_redacted(&self, writer: &mut RedactionWriter<'_>)
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
impl Serialize for MetadataSchema
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 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.