pub struct Serial(pub u32);
Expand description
A serial number.
Serial numbers are regular integers with a special notion for comparison in order to be able to deal with roll-over.
Specifically, addition and comparison are defined in RFC 1982.
Addition, however, is only defined for values up to 2^31 - 1
, so we
decided to not implement the Add
trait but rather have a dedicated
method add
so as to not cause surprise panics.
Serial numbers only implement a partial ordering. That is, there are
pairs of values that are not equal but there still isn’t one value larger
than the other. Since this is neatly implemented by the PartialOrd
trait, the type implements that.
Tuple Fields
0: u32
Implementations
sourceimpl Serial
impl Serial
pub fn from_be(value: u32) -> Self
pub fn to_be(self) -> u32
sourcepub fn add(self, other: u32) -> Self
pub fn add(self, other: u32) -> Self
Add other
to self
.
Serial numbers only allow values of up to 2^31 - 1
to be added to
them. Therefore, this method requires other
to be a u32
instead
of a Serial
to indicate that you cannot simply add two serials
together. This is also why we don’t implement the Add
trait.
Panics
This method panics if other
is greater than 2^31 - 1
.
Trait Implementations
sourceimpl PartialEq<Serial> for Serial
impl PartialEq<Serial> for Serial
sourceimpl PartialEq<u32> for Serial
impl PartialEq<u32> for Serial
sourceimpl PartialOrd<Serial> for Serial
impl PartialOrd<Serial> for Serial
sourcefn partial_cmp(&self, other: &Serial) -> Option<Ordering>
fn partial_cmp(&self, other: &Serial) -> Option<Ordering>
This method returns an ordering between self
and other
values if one exists. Read more
1.0.0 · sourcefn lt(&self, other: &Rhs) -> bool
fn lt(&self, other: &Rhs) -> bool
This method tests less than (for self
and other
) and is used by the <
operator. Read more
1.0.0 · sourcefn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
impl Copy for Serial
impl Eq for Serial
Auto Trait Implementations
impl RefUnwindSafe for Serial
impl Send for Serial
impl Sync for Serial
impl Unpin for Serial
impl UnwindSafe for Serial
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more