Skip to main content

qubit_metadata/
lib.rs

1/*******************************************************************************
2 *
3 *    Copyright (c) 2025 - 2026.
4 *    Haixing Hu, Qubit Co. Ltd.
5 *
6 *    All rights reserved.
7 *
8 ******************************************************************************/
9//! # qubit-metadata
10//!
11//! A general-purpose, type-safe, extensible metadata model for Rust.
12//!
13//! This crate provides a [`Metadata`] type — a structured key-value store
14//! designed for any domain that needs to attach arbitrary, typed, serializable
15//! annotations to its data models. It is not a plain `HashMap` — it is a
16//! structured extensibility point with type-safe access, `serde_json::Value`
17//! backing, and first-class `serde` support.
18//!
19//! ## Design Goals
20//!
21//! - **Type Safety**: Typed get/set API backed by `serde_json::Value`
22//! - **Generality**: No domain-specific assumptions — usable in any Rust project
23//! - **Extensibility**: Acts as a structured extension point, not a stringly-typed bag
24//! - **Serialization**: First-class `serde` support for JSON interchange
25//! - **Filtering**: [`MetadataFilter`] for composable query conditions
26//!
27//! ## Features
28//!
29//! - Core type: [`Metadata`] — an ordered key-value store with typed accessors
30//! - Filter type: [`MetadataFilter`] — composable filter expressions for metadata queries
31//! - Condition type: [`Condition`] — individual comparison predicates
32//! - Error type: [`MetadataError`] — explicit failure reporting for `try_*` APIs
33//! - Type inspection: [`MetadataValueType`] — lightweight JSON value type inspection
34//!
35//! ## Example
36//!
37//! ```rust
38//! use qubit_metadata::{Metadata, MetadataFilter};
39//!
40//! let mut meta = Metadata::new();
41//! meta.set("author", "alice");
42//! meta.set("priority", 3_i64);
43//!
44//! // Convenience API: missing key and type mismatch both collapse to None.
45//! let author: Option<String> = meta.get("author");
46//! assert_eq!(author.as_deref(), Some("alice"));
47//!
48//! // Explicit API: preserve failure reasons for diagnostics.
49//! let priority = meta.try_get::<i64>("priority").unwrap();
50//! assert_eq!(priority, 3);
51//!
52//! let filter = MetadataFilter::equal("author", "alice")
53//!     .and(MetadataFilter::greater_equal("priority", 1_i64));
54//! assert!(filter.matches(&meta));
55//! ```
56//!
57//! ## Author
58//!
59//! Haixing Hu
60
61#![deny(missing_docs)]
62
63mod condition;
64mod metadata;
65mod metadata_error;
66mod metadata_filter;
67mod metadata_result;
68mod metadata_value_type;
69
70pub use condition::Condition;
71pub use metadata::Metadata;
72pub use metadata_error::MetadataError;
73pub use metadata_filter::MetadataFilter;
74pub use metadata_result::MetadataResult;
75pub use metadata_value_type::MetadataValueType;