Skip to main content

SeqSpace

Struct SeqSpace 

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

A modular sequence-number space of bits bits (1..=31).

Implementations§

Source§

impl SeqSpace

Source

pub const fn new(bits: u32) -> Self

A bits-wide space.

§Panics

In a const context (compile error) or at runtime if bits is 0 or exceeds MAX_SEQ_BITS.

Source

pub const fn modulus(self) -> u64

Number of distinct sequence numbers: 2^bits.

Source

pub const fn mask(self) -> u32

Bit mask selecting a sequence number: 2^bits - 1.

Source

pub const fn add(self, seq: u32, n: u32) -> u32

seq + n, wrapping at the space boundary.

Source

pub const fn diff(self, a: u32, b: u32) -> i32

Signed circular distance a - b, in (-half, half] where half is half the space. Positive means a is ahead of b. Inputs are masked to the space.

Source

pub const fn lt(self, a: u32, b: u32) -> bool

a precedes b in circular order.

Source

pub const fn leq(self, a: u32, b: u32) -> bool

a precedes or equals b.

Source

pub const fn gt(self, a: u32, b: u32) -> bool

a follows b in circular order.

Source

pub const fn geq(self, a: u32, b: u32) -> bool

a follows or equals b.

Source

pub const fn in_closed_range(self, seq: u32, first: u32, last: u32) -> bool

seq lies within the inclusive circular range first..=last, walking forward from first. A last that precedes first in circular order is an empty (malformed) range and never matches.

Trait Implementations§

Source§

impl Clone for SeqSpace

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Copy for SeqSpace

Source§

impl Debug for SeqSpace

Source§

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

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

impl Eq for SeqSpace

Source§

impl PartialEq for SeqSpace

Source§

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

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for SeqSpace

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

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.