escriba_core/gen.rs
1//! [`EditGen`] — the monotonic edit-generation stamp.
2//!
3//! One per `EditorState`. It bumps on every state mutation (edit, motion,
4//! mode change, viewport move) and is the root of escriba's sealed refresh
5//! tree (`theory/ESCRIBA.md` §Refresh-Seal): a rendered product is *fresh* iff
6//! its stamp equals the current `EditGen`, so a stale frame — one that shows a
7//! product older than the state it claims — has no reachable code path once
8//! the renderer gates on the stamp. Same monotonic-`u64` technique as mado's
9//! frame seqno, promoted to a typed primitive.
10
11use schemars::JsonSchema;
12use serde::{Deserialize, Serialize};
13
14/// A monotonic edit-generation counter. Equality is the freshness test:
15/// `product_gen == current_gen` ⇒ the product matches the live state.
16#[derive(
17 Clone,
18 Copy,
19 PartialEq,
20 Eq,
21 PartialOrd,
22 Ord,
23 Hash,
24 Debug,
25 Default,
26 Serialize,
27 Deserialize,
28 JsonSchema,
29)]
30pub struct EditGen(pub u64);
31
32impl EditGen {
33 /// The next generation. Wraps (a 64-bit counter at 1 bump/ns lasts ~585
34 /// years; wrap is defensive, never reached).
35 #[must_use]
36 pub fn next(self) -> Self {
37 Self(self.0.wrapping_add(1))
38 }
39}