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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
//! Versioned Rust records with explicit field conversions and frozen schema checks.
//!
//! A shop starts by storing receipts with an amount in US cents. Later, it adds a
//! currency field. New code needs that field, but old receipts still contain only
//! the amount. Type History keeps the old record shape and runs your conversion
//! to supply `"USD"` when those receipts are read.
//!
//! `#[versioned]` generates a Rust struct for each supported version of a record.
//! A new `ReceiptCreated` history starts with `ReceiptCreatedV1`. Later versions
//! add `ReceiptCreatedV2`, `ReceiptCreatedV3`, and so on. The original name aliases
//! the latest struct: at V2, the macro generates `pub type ReceiptCreated = ReceiptCreatedV2;`.
//!
//! Use the alias's `into_versioned` method to create a [`Versioned`] containing
//! the data and its generated metadata.
//! Serialize that record with JSON or named-field MessagePack, and store the
//! bytes where your application chooses. After deserialization, the alias's
//! `from_versioned` method applies the declared conversions and returns the
//! latest type. Application code reads and writes through that alias.
//!
//! After [setting up a library package](https://github.com/sformisano/type-history/blob/v0.3.3/book/src/setup.md),
//! start the receipt history with a stable name:
//!
//! ```rust,ignore
//! use type_history::versioned;
//!
//! #[versioned(stable_name = "shop.receipt.created")]
//! pub struct ReceiptCreated {
//! pub amount_cents: u64,
//! }
//! ```
//!
//! The stable name is frozen with the schemas. Builds reject changes to that value,
//! even when the Rust type or its module is renamed.
//! Frozen schemas protect the stored shape; your conversion functions and tests
//! must preserve what the values mean.
//!
//! Conversions run from older versions to the current version. A consumer built
//! with only V1 rejects a V2 receipt. Services sharing a types crate must therefore
//! coordinate which versions they publish and accept; see the
//! [distributed-system walkthrough](https://github.com/sformisano/type-history/blob/v0.3.3/README.md#using-type-history-in-a-distributed-system).
//!
//! Install the matching 0.3.3 crates from crates.io. The [package setup guide](https://github.com/sformisano/type-history/blob/v0.3.3/book/src/setup.md)
//! shows the matching runtime, build hook, and CLI configuration.
//! The guide configures schema checks and initializes the ledger before any history declaration.
//! The current setup requires Rust 1.97 or later. Type History supports Linux and
//! macOS. Windows is not supported.
//! The [book](https://github.com/sformisano/type-history/blob/v0.3.3/book/README.md)
//! links to field rules, lifecycle commands, and error handling.
//!
//! For existing storage that keeps JSON payloads and metadata separately, the
//! low-level [`decode`] API reads the payload using that metadata. Validate it
//! when reading it from storage:
//!
//! ```
//! # use std::error::Error;
//! use type_history::{PayloadVersion, StableName};
//!
//! let stable_name = StableName::try_from("billing.invoice.issued".to_owned())?;
//! let version = PayloadVersion::try_from(1_u32)?;
//! assert_eq!(stable_name.as_str(), "billing.invoice.issued");
//! assert_eq!(version.get(), 1);
//! assert!(PayloadVersion::try_from(0_u32).is_err());
//! # Ok::<(), Box<dyn Error>>(())
//! ```
//!
//! A receipt may contain another record or an enum. The [`Schema`] derive
//! describes how those supporting types are serialized so changes can be checked
//! against frozen schemas. It supports named records, nonempty tuple structs,
//! and externally tagged enums, including inside supported containers.
//! Keep earlier enum definitions when a containing field
//! changes type; `#[versioned]` remains restricted to concrete named-field structs.
//! [`ResolvedSchema`], [`JsonSchemaField`], and [`FieldSchema`] provide the
//! underlying schema description and export traits.
//!
//! String-keyed hash/tree maps share a storage contract. Sets carry an explicit
//! [`SetMembership`] contract and differ from vectors. Custom membership IDs are
//! trusted declarations of equality; schema derivation does not verify custom
//! `Eq`, `Hash`, or `Ord`. A membership change requires a versioned field update.
//! Bare tuples support arities 1 through 16. Owned `Box` values preserve the inner
//! contract; feature `rc` adds `Rc` and `Arc` by value.
//! Histories containing tuples above arity 12 must set `derive_debug = false`
//! and `derive_partial_eq = false`.
//!
//! Optional features `typed-floats`, `uuid`, `rust-decimal`, `chrono`, and `time`
//! add finite numeric types and checked [`adapters`]. Defaults are empty. Adapters
//! own their serialization, so native dependencies' Serde features do not change
//! stored profiles. See the [field integration guide](https://github.com/sformisano/type-history/blob/v0.3.3/book/src/integration.md).
extern crate self as type_history;
pub use ;
pub use ;
pub use ;
/// Dependencies addressed by generated code.