Skip to main content

Crate qubit_metadata

Crate qubit_metadata 

Source
Expand description

§qubit-metadata

A general-purpose, type-safe, extensible metadata model for Rust.

This crate provides a Metadata type — a structured key-value store designed for any domain that needs to attach typed annotations to its data models. It is not a plain HashMap — it is a structured extensibility point with type-safe access, qubit_value::Value backing, and first-class serde support.

§Design Goals

  • Type Safety: Typed get/set API backed by qubit_value::Value
  • Generality: No domain-specific assumptions — usable in any Rust project
  • Schema Support: Optional MetadataSchema validation for metadata and filters
  • Serialization: First-class serde support for JSON interchange
  • Filtering: MetadataFilter for composable query conditions

§Features

§Example

use qubit_metadata::{Metadata, MetadataFilter};

let meta = Metadata::new()
    .with("author", "alice")
    .with("priority", 3_i64);

// Convenience API: missing key and type mismatch both collapse to None.
let author: Option<String> = meta.get("author");
assert_eq!(author.as_deref(), Some("alice"));

// Explicit API: preserve failure reasons for diagnostics.
let priority = meta.try_get::<i64>("priority").unwrap();
assert_eq!(priority, 3);

let filter = MetadataFilter::builder()
    .eq("author", "alice")
    .and_ge("priority", 1_i64)
    .build()
    .unwrap();
assert!(filter.matches(&meta));

§Author

Haixing Hu

Structs§

FilterMatchOptions
Match policies used when evaluating a crate::MetadataFilter.
Metadata
A structured, ordered, typed key-value store for metadata fields.
MetadataField
Definition of one metadata field in a crate::MetadataSchema.
MetadataFilter
An immutable, composable filter expression over Metadata.
MetadataFilterBuilder
Builder for MetadataFilter.
MetadataSchema
Schema for metadata fields.
MetadataSchemaBuilder
Builder for MetadataSchema.

Enums§

Condition
A single comparison operator applied to one metadata key.
MetadataError
Errors produced by explicit metadata accessors and schema validation.
MissingKeyPolicy
Policy that controls how filters treat missing keys for negative predicates.
NumberComparisonPolicy
Policy that controls mixed integer/float number comparisons.
UnknownFieldPolicy
Policy for fields that appear in metadata but are not declared by a schema.

Type Aliases§

MetadataResult
Result type used by explicit Metadata operations that report failure reasons instead of collapsing them into None.