Skip to main content

Sequence

Struct Sequence 

Source
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

ConstantValueMeaning
NULLi64::MINNo sequence exists (SBE null convention)
UNINITIALIZED-1Not yet assigned
ZERO0Starting 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

Source

pub const NULL: Self

SBE-compatible null — i64::MIN. Indicates no sequence exists.

Maps directly to the SBE int64 null sentinel on the wire.

Source

pub const UNINITIALIZED: Self

Uninitialized sentinel — -1. Indicates a sequence has not yet been assigned.

Source

pub const ZERO: Self

The zero sequence — the starting point before any events.

Source

pub const fn new(value: i64) -> Self

Create a sequence from a raw i64 value.

Use for construction in tests, deserialization, or replay.

Source

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.

Source

pub const fn as_i64(self) -> i64

Returns the raw i64 value.

Use for logging, metrics, serialization, or passing to external systems.

Source

pub const fn is_null(self) -> bool

Returns true if this is the NULL sentinel.

Source

pub const fn is_uninitialized(self) -> bool

Returns true if this is the UNINITIALIZED sentinel.

Source

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.

Source

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.

Trait Implementations§

Source§

impl Clone for Sequence

Source§

fn clone(&self) -> Sequence

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Sequence

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Sequence

Source§

fn default() -> Sequence

Returns the “default value” for a type. Read more
Source§

impl Display for Sequence

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for Sequence

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl Ord for Sequence

Source§

fn cmp(&self, other: &Sequence) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for Sequence

Source§

fn eq(&self, other: &Sequence) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for Sequence

Source§

fn partial_cmp(&self, other: &Sequence) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Sequence

Source§

impl Eq for Sequence

Source§

impl StructuralPartialEq for Sequence

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.