Skip to main content

SequenceManager

Struct SequenceManager 

Source
pub struct SequenceManager { /* private fields */ }
Expand description

Manages sequence numbers for a FIX session.

Uses atomic operations for thread-safe access without locks.

Implementations§

Source§

impl SequenceManager

Source

pub fn new() -> Self

Creates a new sequence manager with sequence numbers starting at 1.

Source

pub fn with_initial(sender_seq: u64, target_seq: u64) -> Self

Creates a new sequence manager with specified starting values.

§Arguments
  • sender_seq - Initial sender sequence number
  • target_seq - Initial target sequence number
Source

pub fn next_sender_seq(&self) -> SeqNum

Returns the next sender sequence number without incrementing.

Source

pub fn next_target_seq(&self) -> SeqNum

Returns the next target sequence number without incrementing.

Source

pub fn allocate_sender_seq(&self) -> SeqNum

Allocates and returns the next sender sequence number.

This atomically increments the sequence number and returns the value before the increment.

Note: wraps silently on u64 overflow. Prefer try_allocate_sender_seq for venue-grade sessions where exhaustion must be an explicit error.

Source

pub fn try_allocate_sender_seq(&self) -> Result<SeqNum, SequenceExhausted>

Allocates and returns the next sender sequence number, failing instead of wrapping when the counter is exhausted.

On success this atomically increments the counter and returns the value before the increment. On exhaustion the counter is left untouched; the session must perform a sequence reset (see SequenceExhausted) before more numbers can be allocated.

§Errors

Returns SequenceExhausted if the counter has reached u64::MAX.

Source

pub fn increment_target_seq(&self)

Increments the target sequence number.

Call this after successfully processing an incoming message.

Note: wraps silently on u64 overflow. Prefer try_increment_target_seq for venue-grade sessions where exhaustion must be an explicit error.

Source

pub fn try_increment_target_seq(&self) -> Result<SeqNum, SequenceExhausted>

Increments the target sequence number, failing instead of wrapping when the counter is exhausted.

On success returns the new next expected target sequence number. On exhaustion the counter is left untouched; the session must perform a sequence reset (see SequenceExhausted) before more messages can be accepted.

§Errors

Returns SequenceExhausted if the counter has reached u64::MAX.

Source

pub fn set_sender_seq(&self, seq: u64)

Sets the next sender sequence number.

§Arguments
  • seq - The new sequence number
Source

pub fn set_target_seq(&self, seq: u64)

Sets the next target sequence number.

§Arguments
  • seq - The new sequence number
Source

pub fn reset(&self)

Resets both sequence numbers to 1.

Source

pub fn validate_incoming(&self, received: u64) -> SequenceResult

Validates an incoming sequence number.

§Arguments
  • received - The received sequence number
§Returns
  • Ok(()) if the sequence number matches expected
  • Err(SequenceResult::TooLow) if it’s a possible duplicate
  • Err(SequenceResult::Gap) if there’s a gap

Trait Implementations§

Source§

impl Debug for SequenceManager

Source§

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

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

impl Default for SequenceManager

Source§

fn default() -> Self

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

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> 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, 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.