1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
/*******************************************************************************
*
* Copyright (c) 2025 - 2026 Haixing Hu.
*
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0.
*
******************************************************************************/
//! # 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
//!
//! - Core type: [`Metadata`] — an ordered key-value store with typed accessors
//! - Schema type: [`MetadataSchema`] — field definitions based on [`qubit_datatype::DataType`]
//! - Filter type: [`MetadataFilter`] — composable filter expressions for metadata queries
//! - Condition type: [`Condition`] — individual comparison predicates
//! - Error type: [`MetadataError`] — explicit failure reporting for `try_*` APIs
//!
//! ## Example
//!
//! ```rust
//! 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));
//! ```
//!
pub use Condition;
pub use FilterMatchOptions;
pub use MetadataFilter;
pub use MetadataFilterBuilder;
pub use MissingKeyPolicy;
pub use NumberComparisonPolicy;
pub use Metadata;
pub use MetadataError;
pub use MetadataResult;
pub use MetadataField;
pub use MetadataSchema;
pub use MetadataSchemaBuilder;
pub use UnknownFieldPolicy;