pub struct SequenceGenerator { /* private fields */ }Expand description
Per-workspace sequence and wall-clock generator.
Guarantees:
seqis strictly monotonically increasing (starts at 1).wall_clock_msis non-decreasing:max(now_ms, last_seen + 1).
§Usage
ⓘ
let mut seq_gen = SequenceGenerator::new();
let (seq, wall_ms) = seq_gen.next(); // (1, now_ms)
let (seq, wall_ms) = seq_gen.next(); // (2, max(now_ms, prev+1))Implementations§
Source§impl SequenceGenerator
impl SequenceGenerator
Sourcepub const fn resume(last_seq: u64, last_wall_clock_ms: u64) -> Self
pub const fn resume(last_seq: u64, last_wall_clock_ms: u64) -> Self
Resume from a known state (e.g., loaded from persistent storage).
Sourcepub fn next(&mut self) -> (u64, u64)
pub fn next(&mut self) -> (u64, u64)
Generate the next (seq, wall_clock_ms) pair.
Wall clock is clamped: if the system clock went backward (NTP step,
VM resume), we use last_seen + 1 instead of going backward.
Sourcepub fn next_with_clock(&mut self, now_ms: u64) -> (u64, u64)
pub fn next_with_clock(&mut self, now_ms: u64) -> (u64, u64)
Generate the next (seq, wall_clock_ms) pair using a provided wall clock.
This is primarily for testing — in production use Self::next().
Sourcepub const fn last_wall_clock_ms(&self) -> u64
pub const fn last_wall_clock_ms(&self) -> u64
The last wall-clock value generated (0 if none yet).
Trait Implementations§
Source§impl Clone for SequenceGenerator
impl Clone for SequenceGenerator
Source§fn clone(&self) -> SequenceGenerator
fn clone(&self) -> SequenceGenerator
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for SequenceGenerator
impl Debug for SequenceGenerator
Source§impl Default for SequenceGenerator
impl Default for SequenceGenerator
Source§impl<'de> Deserialize<'de> for SequenceGenerator
impl<'de> Deserialize<'de> for SequenceGenerator
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for SequenceGenerator
impl RefUnwindSafe for SequenceGenerator
impl Send for SequenceGenerator
impl Sync for SequenceGenerator
impl Unpin for SequenceGenerator
impl UnsafeUnpin for SequenceGenerator
impl UnwindSafe for SequenceGenerator
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more