Skip to main content

Serial

Struct Serial 

Source
pub struct Serial<T>(/* private fields */);
Expand description

A wraparound serial number.

§Example

use serial_uint::Serial;

let a = Serial::<u8>::new(250);
let b = a + 10; // wraparound: 250 + 10 = 4
assert_eq!(b.value(), 4);
assert!(a < b); // wraparound comparison: a precedes b

Implementations§

Source§

impl<T: SerialPrimitive> Serial<T>

Source

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

Constructs a serial number from a raw value.

Source

pub fn value(self) -> T

Returns the underlying raw value.

Source

pub fn distance_to(self, other: Self) -> T

The forward wraparound distance from self to other, i.e. other - self (wraparound).

The result lies in [0, MAX] and is always non-negative. For example, for u8 the distance from 250 to 4 is 10.

Source

pub fn precedes(self, other: Self) -> bool

Returns whether self precedes other (in the wraparound sense).

Returns false when the two are exactly half a cycle apart and their ordering is undefined.

Trait Implementations§

Source§

impl<T: SerialPrimitive> Add<T> for Serial<T>

Source§

fn add(self, rhs: T) -> Serial<T>

Adds an offset (wraparound).

Per RFC 1982 the addend must be in [0, HALF - 1]; larger values are undefined. This is checked with debug_assert! (debug builds only) and otherwise still wraps.

Source§

type Output = Serial<T>

The resulting type after applying the + operator.
Source§

impl<T: SerialPrimitive> AddAssign<T> for Serial<T>

Source§

fn add_assign(&mut self, rhs: T)

Performs the += operation. Read more
Source§

impl<T: Clone> Clone for Serial<T>

Source§

fn clone(&self) -> Serial<T>

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<T: Copy> Copy for Serial<T>

Source§

impl<T: Debug> Debug for Serial<T>

Source§

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

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

impl<T: Default> Default for Serial<T>

Source§

fn default() -> Serial<T>

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

impl<T: SerialPrimitive + Display> Display for Serial<T>

Forwards to the underlying value’s Display, so a serial number prints just like its raw value.

Source§

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

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

impl<T: Eq> Eq for Serial<T>

Source§

impl<T: Hash> Hash for Serial<T>

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<T: PartialEq> PartialEq for Serial<T>

Source§

fn eq(&self, other: &Serial<T>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Serial<u8>> for u8

Compare equality directly against the underlying raw value: raw == serial.

Source§

fn eq(&self, other: &Serial<u8>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Serial<u16>> for u16

Compare equality directly against the underlying raw value: raw == serial.

Source§

fn eq(&self, other: &Serial<u16>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Serial<u32>> for u32

Compare equality directly against the underlying raw value: raw == serial.

Source§

fn eq(&self, other: &Serial<u32>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Serial<u64>> for u64

Compare equality directly against the underlying raw value: raw == serial.

Source§

fn eq(&self, other: &Serial<u64>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Serial<u128>> for u128

Compare equality directly against the underlying raw value: raw == serial.

Source§

fn eq(&self, other: &Serial<u128>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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 PartialEq<Serial<usize>> for usize

Compare equality directly against the underlying raw value: raw == serial.

Source§

fn eq(&self, other: &Serial<usize>) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<T: SerialPrimitive> PartialEq<T> for Serial<T>

Compare equality directly against the underlying raw value: serial == raw.

Source§

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

Tests for self and other values to be equal, and is used by ==.
1.0.0 (const: unstable) · 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<T: SerialPrimitive> PartialOrd for Serial<T>

Source§

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

RFC 1982 wraparound comparison.

Let the wraparound difference be d = other - self (wraparound):

  • d == 0 → equal
  • 0 < d < HALFself < other
  • d > HALFself > other
  • d == HALF → undefined, returns None
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 PartialOrd<Serial<u8>> for u8

Wraparound ordering against a serial number: raw <cmp> serial.

The raw value is treated as Serial(raw), so the comparison uses RFC 1982 wraparound semantics (and yields None when half a cycle apart).

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 PartialOrd<Serial<u16>> for u16

Wraparound ordering against a serial number: raw <cmp> serial.

The raw value is treated as Serial(raw), so the comparison uses RFC 1982 wraparound semantics (and yields None when half a cycle apart).

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 PartialOrd<Serial<u32>> for u32

Wraparound ordering against a serial number: raw <cmp> serial.

The raw value is treated as Serial(raw), so the comparison uses RFC 1982 wraparound semantics (and yields None when half a cycle apart).

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 PartialOrd<Serial<u64>> for u64

Wraparound ordering against a serial number: raw <cmp> serial.

The raw value is treated as Serial(raw), so the comparison uses RFC 1982 wraparound semantics (and yields None when half a cycle apart).

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 PartialOrd<Serial<u128>> for u128

Wraparound ordering against a serial number: raw <cmp> serial.

The raw value is treated as Serial(raw), so the comparison uses RFC 1982 wraparound semantics (and yields None when half a cycle apart).

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 PartialOrd<Serial<usize>> for usize

Wraparound ordering against a serial number: raw <cmp> serial.

The raw value is treated as Serial(raw), so the comparison uses RFC 1982 wraparound semantics (and yields None when half a cycle apart).

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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<T: SerialPrimitive> PartialOrd<T> for Serial<T>

Wraparound ordering against a raw value: serial <cmp> raw.

The raw value is treated as Serial(raw), so the comparison uses RFC 1982 wraparound semantics (and yields None when half a cycle apart).

Source§

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

This method returns an ordering between self and other values if one exists. Read more
1.0.0 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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 (const: unstable) · 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<T: PartialEq> StructuralPartialEq for Serial<T>

Source§

impl<T: SerialPrimitive> Sub<T> for Serial<T>

Source§

fn sub(self, rhs: T) -> Serial<T>

Subtracts an offset (wraparound).

Source§

type Output = Serial<T>

The resulting type after applying the - operator.
Source§

impl<T: SerialPrimitive> SubAssign<T> for Serial<T>

Source§

fn sub_assign(&mut self, rhs: T)

Performs the -= operation. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Serial<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Serial<T>
where T: RefUnwindSafe,

§

impl<T> Send for Serial<T>
where T: Send,

§

impl<T> Sync for Serial<T>
where T: Sync,

§

impl<T> Unpin for Serial<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Serial<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Serial<T>
where T: UnwindSafe,

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