pub struct Sequence(/* private fields */);Expand description
Monotonic event sequence number for event ordering.
Each event processed by a driver is assigned a unique sequence number
via World::next_sequence. Handlers can read the current sequence
via Seq or advance it via SeqMut.
Uses i64 for wire-format compatibility (FIX/SBE, Protobuf, Avro
all have native signed 64-bit; unsigned is awkward or absent) and to
support sentinel values (NULL,
UNINITIALIZED) without Option overhead.
Wrapping is harmless — at one increment per event, the positive i64
space takes ~292 years at 1 GHz to exhaust.
§Sentinels
| Constant | Value | Meaning |
|---|---|---|
NULL | i64::MIN | No sequence exists (SBE null convention) |
UNINITIALIZED | -1 | Not yet assigned |
ZERO | 0 | Starting point before any events |
§Examples
use nexus_rt::Sequence;
let a = Sequence::ZERO;
let b = a.next();
assert!(b > a);
assert_eq!(b.as_i64(), 1);
assert_eq!(b.elapsed_since(a), 1);
assert!(Sequence::NULL.is_null());
assert!(!Sequence::ZERO.is_null());Implementations§
Source§impl Sequence
impl Sequence
Sourcepub const NULL: Self
pub const NULL: Self
SBE-compatible null — i64::MIN. Indicates no sequence exists.
Maps directly to the SBE int64 null sentinel on the wire.
Sourcepub const UNINITIALIZED: Self
pub const UNINITIALIZED: Self
Uninitialized sentinel — -1. Indicates a sequence has not yet
been assigned.
Sourcepub const fn new(value: i64) -> Self
pub const fn new(value: i64) -> Self
Create a sequence from a raw i64 value.
Use for construction in tests, deserialization, or replay.
Sourcepub const fn from_i64(value: i64) -> Self
pub const fn from_i64(value: i64) -> Self
Create a sequence from a raw i64 value.
Symmetric with as_i64. Use for wire protocol
deserialization.
Sourcepub const fn as_i64(self) -> i64
pub const fn as_i64(self) -> i64
Returns the raw i64 value.
Use for logging, metrics, serialization, or passing to external systems.
Sourcepub const fn is_uninitialized(self) -> bool
pub const fn is_uninitialized(self) -> bool
Returns true if this is the UNINITIALIZED sentinel.
Sourcepub const fn next(self) -> Self
pub const fn next(self) -> Self
Returns the next sequence number (wrapping).
This is a pure computation — it does not advance any world state.
Use World::next_sequence to actually advance the world’s
current sequence.
Sourcepub const fn elapsed_since(self, earlier: Self) -> i64
pub const fn elapsed_since(self, earlier: Self) -> i64
Returns the number of events between earlier and self.
Wrapping-aware: if self has wrapped past earlier, the result
is the wrapping distance. Returns 0 if self == earlier.