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.
Sourcepub fn saturating_add(self, d: Duration) -> Self
pub fn saturating_add(self, d: Duration) -> Self
Like Duration::saturating_add
.
Sourcepub fn saturating_mul(self, m: NonZeroU32) -> Self
pub fn saturating_mul(self, m: NonZeroU32) -> Self
Like Duration::saturating_mul
.
Trait Implementations§
Source§impl Add<Duration> for NonZeroDuration
impl Add<Duration> for NonZeroDuration
Source§impl Add for NonZeroDuration
impl Add for NonZeroDuration
Source§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
Source§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§impl PartialOrd for NonZeroDuration
impl PartialOrd for NonZeroDuration
impl Copy for NonZeroDuration
impl Eq for NonZeroDuration
impl StructuralPartialEq for NonZeroDuration
Auto Trait Implementations§
impl Freeze for NonZeroDuration
impl RefUnwindSafe for NonZeroDuration
impl Send for NonZeroDuration
impl Sync for NonZeroDuration
impl Unpin for NonZeroDuration
impl UnwindSafe for NonZeroDuration
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> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§unsafe fn clone_to_uninit(&self, dst: *mut T)
unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)