Skip to main content

continuity_buffer/
revision.rs

1//! The per-buffer revision counter.
2//!
3//! Every accepted edit advances the revision. Decoration results, channel
4//! messages, and persisted edit log rows all carry the revision they were
5//! computed against — receivers that find the buffer has advanced past their
6//! revision discard their stale work.
7
8/// A monotonically increasing revision number for a buffer.
9#[derive(Copy, Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Default)]
10pub struct Revision(pub u64);
11
12impl Revision {
13    /// The revision of a freshly-created buffer.
14    pub const INITIAL: Self = Self(0);
15
16    /// The next revision after `self`.
17    #[must_use]
18    pub const fn next(self) -> Self {
19        Self(self.0 + 1)
20    }
21
22    /// Borrow the inner counter for serialization.
23    #[must_use]
24    pub const fn get(self) -> u64 {
25        self.0
26    }
27}
28
29#[cfg(test)]
30mod tests {
31    use super::*;
32
33    #[test]
34    fn next_increments_by_one() {
35        assert_eq!(Revision::INITIAL.next(), Revision(1));
36        assert_eq!(Revision(7).next(), Revision(8));
37    }
38
39    #[test]
40    fn ordering_is_numeric() {
41        assert!(Revision(0) < Revision(1));
42        assert!(Revision(99) > Revision(98));
43    }
44}