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§
source§impl Serial
impl Serial
pub const fn from_be(value: u32) -> Self
pub const 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§
source§impl<'arbitrary> Arbitrary<'arbitrary> for Serial
impl<'arbitrary> Arbitrary<'arbitrary> for Serial
source§fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>
fn arbitrary(u: &mut Unstructured<'arbitrary>) -> Result<Self>
Self
from the given unstructured data. Read moresource§fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>
fn arbitrary_take_rest(u: Unstructured<'arbitrary>) -> Result<Self>
Self
from the entirety of the given
unstructured data. Read moresource§impl PartialEq for Serial
impl PartialEq for Serial
source§impl PartialOrd for Serial
impl PartialOrd for Serial
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
self
and other
) and is used by the <=
operator. Read moreimpl Copy for Serial
impl Eq for Serial
Auto Trait Implementations§
impl Freeze for Serial
impl RefUnwindSafe for Serial
impl Send for Serial
impl Sync for Serial
impl Unpin for Serial
impl UnwindSafe for Serial
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> Text for Twhere
T: Display,
impl<T> Text for Twhere
T: Display,
source§fn write_escaped(
&self,
mode: TextEscape,
target: &mut impl Write,
) -> Result<(), Error>
fn write_escaped( &self, mode: TextEscape, target: &mut impl Write, ) -> Result<(), Error>
target
.