muniment/journal/seq.rs
1// Copyright 2026 Mark Alan Boykin
2// This Source Code Form is subject to the terms of the Mozilla Public
3// License, v. 2.0. If a copy of the MPL was not distributed with this
4// file, You can obtain one at https://mozilla.org/MPL/2.0/.
5// SPDX-License-Identifier: MPL-2.0
6
7//! Entry sequence numbers.
8
9use serde::{Deserialize, Serialize};
10
11/// The position of an entry in a [`Journal`](super::Journal). Zero-based: the
12/// first appended entry is `Seq(0)`.
13///
14/// Monotonic and stable. Because entries are never removed or reordered, a
15/// `Seq` refers to the same entry for the life of the log, so it is a durable
16/// cursor a peer or a reader can hold across sessions.
17#[derive(
18 Clone, Copy, Debug, Default, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
19)]
20pub struct Seq(pub u64);
21
22impl Seq {
23 /// The entry index this sequence addresses.
24 pub fn index(self) -> usize {
25 self.0 as usize
26 }
27
28 /// The next sequence after this one.
29 pub fn next(self) -> Seq {
30 Seq(self.0 + 1)
31 }
32}