pub struct Duration_type { /* private fields */ }
Expand description
Represents a duration of time.
A duration is the amount of time between two instants. It can only be positive.
Its maximum precision is nanoseconds.
It is deeply inspired by the core::time::Duration
type.
Implementations§
Source§impl Duration_type
impl Duration_type
Sourcepub const fn New(Seconds: u64, Nanoseconds: u32) -> Self
pub const fn New(Seconds: u64, Nanoseconds: u32) -> Self
Creates a new Duration_type
from the specified number of seconds and nanoseconds.
Sourcepub fn Get_duration_since(&self, Earlier: &Duration_type) -> Duration_type
pub fn Get_duration_since(&self, Earlier: &Duration_type) -> Duration_type
Returns the duration between the two instants.
§Example
use Shared::Duration_type;
let earlier = Duration_type::New(1, 0);
let later = Duration_type::New(2, 0);
let duration = later.Get_duration_since(&earlier);
assert_eq!(duration, Duration_type::New(1, 0));
let duration = earlier.Get_duration_since(&later);
assert_eq!(duration, Duration_type::New(0, 0));
Sourcepub fn Get_duration_since_checked(
&self,
Earlier: &Duration_type,
) -> Option<Duration_type>
pub fn Get_duration_since_checked( &self, Earlier: &Duration_type, ) -> Option<Duration_type>
Returns the duration between the two instants, or None
if the duration is negative.
§Example
use Shared::Duration_type;
let earlier = Duration_type::New(1, 0);
let later = Duration_type::New(2, 0);
let duration = later.Get_duration_since_checked(&earlier);
assert_eq!(duration, Some(Duration_type::New(1, 0)));
let duration = earlier.Get_duration_since_checked(&later);
assert_eq!(duration, None);
Sourcepub fn Get_duration_since_saturating(
&self,
earlier: &Duration_type,
) -> Duration_type
pub fn Get_duration_since_saturating( &self, earlier: &Duration_type, ) -> Duration_type
Returns the duration between the two instants, saturating at the bounds of the type.
§Example
use Shared::Duration_type;
let earlier = Duration_type::New(1, 0);
let later = Duration_type::New(2, 0);
let duration = later.Get_duration_since_saturating(&earlier);
assert_eq!(duration, Duration_type::New(1, 0));
let duration = earlier.Get_duration_since_saturating(&later);
assert_eq!(duration, Duration_type::default());
pub fn Add_checked(&self, Duration: &Duration_type) -> Option<Duration_type>
pub fn Substract_checked( &self, Duration: &Duration_type, ) -> Option<Duration_type>
pub fn Add_saturating(&self, Duration: &Duration_type) -> Duration_type
pub fn Substract_saturating(&self, duration: &Duration_type) -> Duration_type
Sourcepub fn As_seconds(&self) -> u64
pub fn As_seconds(&self) -> u64
Returns the number of seconds in the duration.
§Example
use Shared::Duration_type;
let duration = Duration_type::New(1, 500_000_000);
assert_eq!(duration.As_seconds(), 1);
Sourcepub fn As_milliseconds(&self) -> u64
pub fn As_milliseconds(&self) -> u64
Returns the number of milliseconds in the duration.
§Example
use Shared::Duration_type;
let duration = Duration_type::New(1, 500_000_000);
assert_eq!(duration.As_milliseconds(), 1_500);
Sourcepub fn As_microseconds(&self) -> u128
pub fn As_microseconds(&self) -> u128
Returns the number of microseconds in the duration.
§Example
use Shared::Duration_type;
let duration = Duration_type::New(1, 500_000_000);
assert_eq!(duration.As_microseconds(), 1_500_000);
Sourcepub fn As_nanoseconds(&self) -> u128
pub fn As_nanoseconds(&self) -> u128
Returns the number of nanoseconds in the duration.
§Example
use Shared::Duration_type;
let duration = Duration_type::New(1, 500_000_000);
assert_eq!(duration.As_nanoseconds(), 1_500_000_000);
Trait Implementations§
Source§impl Add<&Duration_type> for Duration_type
impl Add<&Duration_type> for Duration_type
Source§type Output = Duration_type
type Output = Duration_type
The resulting type after applying the
+
operator.Source§fn add(self, Duration: &Duration_type) -> Duration_type
fn add(self, Duration: &Duration_type) -> Duration_type
Performs the
+
operation. Read moreSource§impl AddAssign<&Duration_type> for Duration_type
impl AddAssign<&Duration_type> for Duration_type
Source§fn add_assign(&mut self, Duration: &Duration_type)
fn add_assign(&mut self, Duration: &Duration_type)
Performs the
+=
operation. Read moreSource§impl AsMut<[u8]> for Duration_type
impl AsMut<[u8]> for Duration_type
Source§impl AsRef<[u8]> for Duration_type
impl AsRef<[u8]> for Duration_type
Source§impl Clone for Duration_type
impl Clone for Duration_type
Source§fn clone(&self) -> Duration_type
fn clone(&self) -> Duration_type
Returns a copy of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source
. Read moreSource§impl Debug for Duration_type
impl Debug for Duration_type
Source§impl Default for Duration_type
impl Default for Duration_type
Source§fn default() -> Duration_type
fn default() -> Duration_type
Returns the “default value” for a type. Read more
Source§impl Hash for Duration_type
impl Hash for Duration_type
Source§impl Ord for Duration_type
impl Ord for Duration_type
Source§fn cmp(&self, other: &Duration_type) -> Ordering
fn cmp(&self, other: &Duration_type) -> Ordering
1.21.0 · Source§fn max(self, other: Self) -> Selfwhere
Self: Sized,
fn max(self, other: Self) -> Selfwhere
Self: Sized,
Compares and returns the maximum of two values. Read more
Source§impl PartialEq for Duration_type
impl PartialEq for Duration_type
Source§impl PartialOrd for Duration_type
impl PartialOrd for Duration_type
Source§impl Sub<&Duration_type> for Duration_type
impl Sub<&Duration_type> for Duration_type
Source§type Output = Duration_type
type Output = Duration_type
The resulting type after applying the
-
operator.Source§fn sub(self, Duration: &Duration_type) -> Duration_type
fn sub(self, Duration: &Duration_type) -> Duration_type
Performs the
-
operation. Read moreSource§impl SubAssign<&Duration_type> for Duration_type
impl SubAssign<&Duration_type> for Duration_type
Source§fn sub_assign(&mut self, Duration: &Duration_type)
fn sub_assign(&mut self, Duration: &Duration_type)
Performs the
-=
operation. Read moreimpl Eq for Duration_type
impl StructuralPartialEq for Duration_type
Auto Trait Implementations§
impl Freeze for Duration_type
impl RefUnwindSafe for Duration_type
impl Send for Duration_type
impl Sync for Duration_type
impl Unpin for Duration_type
impl UnwindSafe for Duration_type
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
Mutably borrows from an owned value. Read more