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
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
//! Persistence edge layer for the mnesis event-sourcing kernel.
//!
//! `mnesis-store` sits between the pure-domain kernel (`mnesis`) and the
//! storage adapters (`mnesis-fjall`, future postgres, etc.). It owns the
//! shapes that cross the kernel↔storage boundary — envelopes, codecs,
//! event streams, repositories, and snapshot stores — and the wire-format
//! row builder every adapter is required to use.
//!
//! # Crate layout
//!
//! Flat: one file per concept, no module subdirectories. Each module's
//! own `//!` header documents its rationale.
//!
//! - [`codec`] — one [`Encode<E>`](crate::Encode) trait and one
//! [`Decode<E>`](crate::Decode) trait with an `Output<'a>` GAT. The GAT
//! collapses what used to be two traits (`Decode` + `BorrowingDecode`)
//! into a single shape that covers both owning serde codecs and
//! borrowing codecs (rkyv, bytemuck). Feature-gated codec impls
//! (`serde`, `json`, `bytemuck`, `rkyv`) ship with the crate.
//! - [`envelope`] — [`PendingEnvelope`] (write path, typestate-built) and
//! [`PersistedEnvelope`] (read path, owned [`bytes::Bytes`] + cached
//! `Range<u32>` offsets). The read envelope is cheap-to-clone (Arc
//! refcount + range copies) and has no lifetime parameter, so it flows
//! through `futures::Stream` items without bridging code.
//! - [`store`] — adapter-facing [`RawEventStore`] trait,
//! [`Store<S>`](crate::store::Store) shared handle, and [`AllPosition`]
//! (the adapter-defined `$all` resume position — the concrete type lives in
//! each adapter, only the trait here).
//! - [`subscription`] — user-facing [`Subscription<S>`] struct (built
//! via `Subscription::new(&store)`). Its `subscribe` / `subscribe_all`
//! methods assemble the generic catch-up-then-live-tail loop from
//! [`RawEventStore`] + [`WakeSource`](crate::wake::WakeSource); there is
//! no adapter-facing subscription trait. The returned cursor is `!Unpin`
//! (consumers `pin!` it).
//! - [`stream`] — [`EventStream`] marker trait over
//! `futures::Stream<Item = Result<PersistedEnvelope, _>>`. The marker
//! carries no methods of its own — every combinator comes from
//! [`futures::StreamExt`](https://docs.rs/futures/latest/futures/stream/trait.StreamExt.html)
//! and [`TryStreamExt`](https://docs.rs/futures/latest/futures/stream/trait.TryStreamExt.html).
//! - [`wire`] — single canonical frame builder
//! ([`encode_frame`](crate::wire::encode_frame)) that every adapter must use.
//! Guarantees 16-byte payload alignment as a wire-format invariant —
//! the precondition zero-copy decoders (rkyv, flatbuffers, `#[repr(C)]`
//! POD) rely on for sound `&T` reads.
//! - [`repository`] / [`builder`] — aggregate-facing [`Repository<A>`]
//! trait plus its facade impl ([`EventStore`], one terminal for both
//! owning and borrowing codecs), constructed via the
//! [`RepositoryBuilder`] typestate.
//! - [`state`] — [`SnapshotStore<S, P>`](crate::SnapshotStore) for atomic
//! state+position persistence. Powers both aggregate snapshots and
//! projection state — same trait, different position type
//! ([`Version`] for a single stream vs an adapter's [`AllPosition`] for a
//! multi-stream projection).
//! - [`upcasting`] — schema evolution via the [`Upcaster`] trait and
//! [`EventMorsel`] zero-copy-when-possible data unit.
//! - [`snapshot`] (feature-gated) — decorator that wraps a repository to
//! hydrate from a [`SnapshotStore`] on read and commit on write per a
//! [`PersistTrigger`].
//! - [`projection`] (feature-gated) — [`Projector`] trait (pure fallible
//! fold). mnesis ships no runner; the loop is consumer-owned (see
//! `examples/projection-tokio`).
//!
//! # Feature flags
//!
//! | Feature | Effect |
//! |---|---|
//! | `serde` | Generic serde codec (`SerdeCodec<F>`) |
//! | `json` | `Json` format + `JsonCodec` alias (implies `serde`) |
//! | `bytemuck` | `BytemuckCodec` for `#[repr(C)]` POD types (zero-copy `&E`) |
//! | `rkyv` | `RkyvCodec` for rkyv-archived types (zero-copy `&Archived<E>`) |
//! | `snapshot` | `Snapshotting<R, SS, T>` repository decorator |
//! | `snapshot-json` | `snapshot` + `json` |
//! | `projection` | `Projector` trait |
//! | `projection-json` | `projection` + `json` |
//! | `subscription` | [`Subscription`] catch-up-then-live-tail loop + [`wake`] traits (dep-free; in-process wake impl lives in `mnesis-wake`) |
//!
//! # Design notes
//!
//! The earlier `codec/`, `envelope/`, `upcasting/`, `store/`,
//! `repository/`, `state/`, `projection/` directories were collapsed into
//! single files because each held only a handful of small files with no
//! cohesion benefit. The boundary that matters is the crate boundary
//! (kernel-pure → store-persistence → adapters); the boundary that
//! didn't matter was inside `mnesis-store`.
// The store is alloc-dependent by design (Bytes, Vec, Arc are its working
// vocabulary) — unlike the pure-core kernel, `alloc` is unconditional.
extern crate alloc;
pub
pub
pub
pub use ;
pub use WithSnapshot;
pub use ;
// Re-export `bytes` so downstreams name `mnesis_store::bytes::Bytes` to feed
// `Encode` / the value newtypes, sharing *our* version rather than coupling to
// theirs. Additive (non-breaking).
pub use bytes;
pub use ;
pub use ;
pub use ;
pub use ;
pub use ConflictPredicate;
pub use ;
pub use ;
pub use LoadWithError;
pub use ;
pub use ;
pub use ;
pub use ;
pub use Version;
pub use ;
pub use ;
pub use ;
pub use Snapshotting;
pub use ;
pub use Step;
pub use ;
pub use EventStream;
pub use StreamKey;
// Re-export the `Stream` trait from `futures-core` (the small, near-frozen
// definitional crate) rather than `futures`. `futures::Stream` *is* this trait,
// so our public `EventStream` / `subscribe*` surface is married to
// `futures-core`'s stability, not the churning batteries-included `futures`.
pub use Stream;
pub use Subscription;
pub use EventMorsel;
pub use ;
pub use ;