Struct packet_formats::utils::NonZeroDuration
source · pub struct NonZeroDuration(/* private fields */);
Expand description
A thin wrapper over a Duration
that guarantees that the underlying
Duration
is non-zero.
Implementations§
source§impl NonZeroDuration
impl NonZeroDuration
sourcepub const unsafe fn new_unchecked(d: Duration) -> NonZeroDuration
pub const unsafe fn new_unchecked(d: Duration) -> NonZeroDuration
Creates a non-zero without checking the value.
§Safety
If d
is zero, unsafe code which relies on the invariant that
NonZeroDuration
values are always zero may cause undefined behavior.
sourcepub const fn from_secs(secs: u64) -> Option<NonZeroDuration>
pub const fn from_secs(secs: u64) -> Option<NonZeroDuration>
Creates a new NonZeroDuration
from the specified number of whole
seconds if that number is non-zero.
sourcepub const fn from_nonzero_secs(secs: NonZeroU64) -> NonZeroDuration
pub const fn from_nonzero_secs(secs: NonZeroU64) -> NonZeroDuration
Creates a new NonZeroDuration
from the specified non-zero number of
whole seconds.
sourcepub const fn from_secs_nanos(secs: u64, nanos: u32) -> Option<NonZeroDuration>
pub const fn from_secs_nanos(secs: u64, nanos: u32) -> Option<NonZeroDuration>
Creates a new NonZeroDuration
from the specified number of whole
seconds and additional nanoseconds if the resulting duration is
non-zero.
If the number of nanoseconds is greater than 1 billion (the number of nanoseconds in a second), then it will carry over into the seconds provided.
§Panics
This constructor will panic if the carry from the nanoseconds overflows the seconds counter.
sourcepub const fn from_nonzero_secs_nanos(
secs: NonZeroU64,
nanos: NonZeroU32
) -> NonZeroDuration
pub const fn from_nonzero_secs_nanos( secs: NonZeroU64, nanos: NonZeroU32 ) -> NonZeroDuration
Creates a new NonZeroDuration
from the specified non-zero number of
whole seconds and additional nanoseconds.
If the number of nanoseconds is greater than 1 billion (the number of nanoseconds in a second), then it will carry over into the seconds provided.
§Panics
This constructor will panic if the carry from the nanoseconds overflows the seconds counter.
sourcepub const fn from_millis(millis: u64) -> Option<NonZeroDuration>
pub const fn from_millis(millis: u64) -> Option<NonZeroDuration>
Creates a new NonZeroDuration
from the specified number of
milliseconds if that number is non-zero.
sourcepub const fn from_nonzero_millis(millis: NonZeroU64) -> NonZeroDuration
pub const fn from_nonzero_millis(millis: NonZeroU64) -> NonZeroDuration
Creates a new NonZeroDuration
from the specified non-zero number of
milliseconds.
sourcepub const fn from_micros(micros: u64) -> Option<NonZeroDuration>
pub const fn from_micros(micros: u64) -> Option<NonZeroDuration>
Creates a new NonZeroDuration
from the specified number of
microseconds if that number is non-zero.
sourcepub const fn from_nonzero_micros(micros: NonZeroU64) -> NonZeroDuration
pub const fn from_nonzero_micros(micros: NonZeroU64) -> NonZeroDuration
Creates a new NonZeroDuration
from the specified non-zero number of
microseconds.
sourcepub const fn from_nanos(nanos: u64) -> Option<NonZeroDuration>
pub const fn from_nanos(nanos: u64) -> Option<NonZeroDuration>
Creates a new NonZeroDuration
from the specified number of nanoseconds
if that number is non-zero.
sourcepub const fn from_nonzero_nanos(nanos: NonZeroU64) -> NonZeroDuration
pub const fn from_nonzero_nanos(nanos: NonZeroU64) -> NonZeroDuration
Creates a new NonZeroDuration
from the specified non-zero number of
nanoseconds.
sourcepub const fn new(d: Duration) -> Option<NonZeroDuration>
pub const fn new(d: Duration) -> Option<NonZeroDuration>
Creates a non-zero if the given value is not zero.
Trait Implementations§
source§impl Add<Duration> for NonZeroDuration
impl Add<Duration> for NonZeroDuration
source§impl Add for NonZeroDuration
impl Add for NonZeroDuration
§type Output = NonZeroDuration
type Output = NonZeroDuration
+
operator.source§impl Clone for NonZeroDuration
impl Clone for NonZeroDuration
source§fn clone(&self) -> NonZeroDuration
fn clone(&self) -> NonZeroDuration
1.0.0 · source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source
. Read moresource§impl Debug for NonZeroDuration
impl Debug for NonZeroDuration
source§impl From<NonZeroDuration> for Duration
impl From<NonZeroDuration> for Duration
source§fn from(NonZeroDuration: NonZeroDuration) -> Duration
fn from(NonZeroDuration: NonZeroDuration) -> Duration
source§impl Hash for NonZeroDuration
impl Hash for NonZeroDuration
source§impl Mul<NonZero<u32>> for NonZeroDuration
impl Mul<NonZero<u32>> for NonZeroDuration
§type Output = NonZeroDuration
type Output = NonZeroDuration
*
operator.source§impl Ord for NonZeroDuration
impl Ord for NonZeroDuration
source§fn cmp(&self, other: &NonZeroDuration) -> Ordering
fn cmp(&self, other: &NonZeroDuration) -> Ordering
1.21.0 · source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
source§impl PartialEq for NonZeroDuration
impl PartialEq for NonZeroDuration
source§fn eq(&self, other: &NonZeroDuration) -> bool
fn eq(&self, other: &NonZeroDuration) -> bool
self
and other
values to be equal, and is used
by ==
.source§impl PartialOrd for NonZeroDuration
impl PartialOrd for NonZeroDuration
source§fn partial_cmp(&self, other: &NonZeroDuration) -> Option<Ordering>
fn partial_cmp(&self, other: &NonZeroDuration) -> Option<Ordering>
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 more