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 bImplementations§
Source§impl<T: SerialPrimitive> Serial<T>
impl<T: SerialPrimitive> Serial<T>
Sourcepub fn distance_to(self, other: Self) -> T
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.
Trait Implementations§
Source§impl<T: SerialPrimitive> Add<T> for Serial<T>
impl<T: SerialPrimitive> Add<T> for Serial<T>
Source§impl<T: SerialPrimitive> AddAssign<T> for Serial<T>
impl<T: SerialPrimitive> AddAssign<T> for Serial<T>
Source§fn add_assign(&mut self, rhs: T)
fn add_assign(&mut self, rhs: T)
+= operation. Read moreimpl<T: Copy> Copy for Serial<T>
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.
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.
impl<T: Eq> Eq for Serial<T>
Source§impl PartialEq<Serial<u8>> for u8
Compare equality directly against the underlying raw value: raw == serial.
impl PartialEq<Serial<u8>> for u8
Compare equality directly against the underlying raw value: raw == serial.
Source§impl PartialEq<Serial<u16>> for u16
Compare equality directly against the underlying raw value: raw == serial.
impl PartialEq<Serial<u16>> for u16
Compare equality directly against the underlying raw value: raw == serial.
Source§impl PartialEq<Serial<u32>> for u32
Compare equality directly against the underlying raw value: raw == serial.
impl PartialEq<Serial<u32>> for u32
Compare equality directly against the underlying raw value: raw == serial.
Source§impl PartialEq<Serial<u64>> for u64
Compare equality directly against the underlying raw value: raw == serial.
impl PartialEq<Serial<u64>> for u64
Compare equality directly against the underlying raw value: raw == serial.
Source§impl PartialEq<Serial<u128>> for u128
Compare equality directly against the underlying raw value: raw == serial.
impl PartialEq<Serial<u128>> for u128
Compare equality directly against the underlying raw value: raw == serial.
Source§impl PartialEq<Serial<usize>> for usize
Compare equality directly against the underlying raw value: raw == serial.
impl PartialEq<Serial<usize>> for usize
Compare equality directly against the underlying raw value: raw == serial.
Source§impl<T: SerialPrimitive> PartialEq<T> for Serial<T>
Compare equality directly against the underlying raw value: serial == raw.
impl<T: SerialPrimitive> PartialEq<T> for Serial<T>
Compare equality directly against the underlying raw value: serial == raw.
Source§impl<T: SerialPrimitive> PartialOrd for Serial<T>
impl<T: SerialPrimitive> PartialOrd for Serial<T>
Source§fn partial_cmp(&self, other: &Self) -> Option<Ordering>
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
RFC 1982 wraparound comparison.
Let the wraparound difference be d = other - self (wraparound):
d == 0→ equal0 < d < HALF→self < otherd > HALF→self > otherd == HALF→ undefined, returnsNone
Source§impl PartialOrd<Serial<u8>> for u8
Wraparound ordering against a serial number: raw <cmp> serial.
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§impl PartialOrd<Serial<u16>> for u16
Wraparound ordering against a serial number: raw <cmp> serial.
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§impl PartialOrd<Serial<u32>> for u32
Wraparound ordering against a serial number: raw <cmp> serial.
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§impl PartialOrd<Serial<u64>> for u64
Wraparound ordering against a serial number: raw <cmp> serial.
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§impl PartialOrd<Serial<u128>> for u128
Wraparound ordering against a serial number: raw <cmp> serial.
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§impl PartialOrd<Serial<usize>> for usize
Wraparound ordering against a serial number: raw <cmp> serial.
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§impl<T: SerialPrimitive> PartialOrd<T> for Serial<T>
Wraparound ordering against a raw value: serial <cmp> raw.
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).
impl<T: PartialEq> StructuralPartialEq for Serial<T>
Source§impl<T: SerialPrimitive> Sub<T> for Serial<T>
impl<T: SerialPrimitive> Sub<T> for Serial<T>
Source§impl<T: SerialPrimitive> SubAssign<T> for Serial<T>
impl<T: SerialPrimitive> SubAssign<T> for Serial<T>
Source§fn sub_assign(&mut self, rhs: T)
fn sub_assign(&mut self, rhs: T)
-= operation. Read more