pub struct Duration { /* private fields */ }
Expand description
Represents a duration of time in femtoseconds
The Duration
type is used to represent lengths of time and is
intentionally similar to std::time::Duration
, but which records
time as femtoseconds to keep accurancy when dealing with partial
nanosecond clock divisons.
Implementations§
source§impl Duration
impl Duration
sourcepub const MAX: Self = _
pub const MAX: Self = _
A duration of the maximum possible length in femtoseconds (Femtos::MAX
)
This will be equivalent to either u64::MAX or u128::MAX femtoseconds
sourcepub const FEMTOS_PER_SEC: Femtos = 1_000_000_000_000_000u128
pub const FEMTOS_PER_SEC: Femtos = 1_000_000_000_000_000u128
The number of femtoseconds in 1 second as Femtos
sourcepub const FEMTOS_PER_MILLISEC: Femtos = 1_000_000_000_000u128
pub const FEMTOS_PER_MILLISEC: Femtos = 1_000_000_000_000u128
The number of femtoseconds in 1 millisecond as Femtos
sourcepub const FEMTOS_PER_MICROSEC: Femtos = 1_000_000_000u128
pub const FEMTOS_PER_MICROSEC: Femtos = 1_000_000_000u128
The number of femtoseconds in 1 microsecond as Femtos
sourcepub const FEMTOS_PER_NANOSEC: Femtos = 1_000_000u128
pub const FEMTOS_PER_NANOSEC: Femtos = 1_000_000u128
The number of femtoseconds in 1 nanosecond as Femtos
sourcepub const FEMTOS_PER_PICOSEC: Femtos = 1_000u128
pub const FEMTOS_PER_PICOSEC: Femtos = 1_000u128
The number of femtoseconds in 1 picosecond as Femtos
sourcepub const fn from_secs(secs: u64) -> Self
pub const fn from_secs(secs: u64) -> Self
Creates a new Duration
from the specified number of seconds
§Examples
use femtos::Duration;
let duration = Duration::from_secs(123);
assert_eq!(123, duration.as_secs());
sourcepub const fn from_millis(millisecs: u64) -> Self
pub const fn from_millis(millisecs: u64) -> Self
Creates a new Duration
from the specified number of milliseconds
§Examples
use femtos::Duration;
let duration = Duration::from_millis(123);
assert_eq!(123, duration.as_millis());
sourcepub const fn from_micros(microsecs: u64) -> Self
pub const fn from_micros(microsecs: u64) -> Self
Creates a new Duration
from the specified number of microseconds
§Examples
use femtos::Duration;
let duration = Duration::from_micros(123);
assert_eq!(123, duration.as_micros());
sourcepub const fn from_nanos(nanosecs: u64) -> Self
pub const fn from_nanos(nanosecs: u64) -> Self
Creates a new Duration
from the specified number of nanoseconds
§Examples
use femtos::Duration;
let duration = Duration::from_nanos(123);
assert_eq!(123, duration.as_nanos());
sourcepub const fn from_picos(picosecs: u128) -> Self
pub const fn from_picos(picosecs: u128) -> Self
Creates a new Duration
from the specified number of picoseconds
§Examples
use femtos::Duration;
let duration = Duration::from_picos(123);
assert_eq!(123, duration.as_picos());
sourcepub const fn from_femtos(femtos: Femtos) -> Self
pub const fn from_femtos(femtos: Femtos) -> Self
Creates a new Duration
from the specified number of femtoseconds
§Examples
use femtos::Duration;
let duration = Duration::from_femtos(123);
assert_eq!(123, duration.as_femtos());
sourcepub const fn as_secs(self) -> u64
pub const fn as_secs(self) -> u64
Returns the number of whole seconds contained by this Duration
.
§Examples
use femtos::Duration;
let duration = Duration::from_femtos(123_465_789_012_345_678);
assert_eq!(duration.as_secs(), 123);
sourcepub const fn as_millis(self) -> u64
pub const fn as_millis(self) -> u64
Returns the number of whole milliseconds contained by this Duration
.
§Examples
use femtos::Duration;
let duration = Duration::from_femtos(123_465_789_012_345_678);
assert_eq!(duration.as_millis(), 123_465);
sourcepub const fn as_micros(self) -> u64
pub const fn as_micros(self) -> u64
Returns the number of whole microseconds contained by this Duration
.
§Examples
use femtos::Duration;
let duration = Duration::from_femtos(123_465_789_012_345_678);
assert_eq!(duration.as_micros(), 123_465_789);
sourcepub const fn as_nanos(self) -> u64
pub const fn as_nanos(self) -> u64
Returns the number of whole nanoseconds contained by this Duration
.
§Examples
use femtos::Duration;
let duration = Duration::from_femtos(123_465_789_012_345_678);
assert_eq!(duration.as_nanos(), 123_465_789_012);
sourcepub const fn as_picos(self) -> u128
pub const fn as_picos(self) -> u128
Returns the number of whole picoseconds contained by this Duration
.
§Examples
use femtos::Duration;
let duration = Duration::from_femtos(123_465_789_012_345_678);
assert_eq!(duration.as_picos(), 123_465_789_012_345);
sourcepub const fn as_femtos(self) -> Femtos
pub const fn as_femtos(self) -> Femtos
Returns the number of whole femtoseconds contained by this Duration
.
§Examples
use femtos::Duration;
let duration = Duration::from_femtos(123_465_789_012_345_678);
assert_eq!(duration.as_femtos(), 123_465_789_012_345_678);
sourcepub const fn checked_add(self, rhs: Self) -> Option<Self>
pub const fn checked_add(self, rhs: Self) -> Option<Self>
Checked Duration
addition. Computes self + rhs
, returning None
if an overflow occured.
§Examples
use femtos::{Duration, Femtos};
assert_eq!(Duration::from_secs(1).checked_add(Duration::from_secs(1)), Some(Duration::from_secs(2)));
assert_eq!(Duration::from_secs(1).checked_add(Duration::from_femtos(Femtos::MAX)), None);
sourcepub const fn checked_sub(self, rhs: Self) -> Option<Self>
pub const fn checked_sub(self, rhs: Self) -> Option<Self>
Trait Implementations§
source§impl AddAssign<Duration> for Instant
impl AddAssign<Duration> for Instant
source§fn add_assign(&mut self, rhs: Duration)
fn add_assign(&mut self, rhs: Duration)
+=
operation. Read moresource§impl AddAssign for Duration
impl AddAssign for Duration
source§fn add_assign(&mut self, rhs: Self)
fn add_assign(&mut self, rhs: Self)
+=
operation. Read moresource§impl DivAssign<u32> for Duration
impl DivAssign<u32> for Duration
source§fn div_assign(&mut self, rhs: u32)
fn div_assign(&mut self, rhs: u32)
/=
operation. Read moresource§impl DivAssign<u64> for Duration
impl DivAssign<u64> for Duration
source§fn div_assign(&mut self, rhs: u64)
fn div_assign(&mut self, rhs: u64)
/=
operation. Read moresource§impl MulAssign<u32> for Duration
impl MulAssign<u32> for Duration
source§fn mul_assign(&mut self, rhs: u32)
fn mul_assign(&mut self, rhs: u32)
*=
operation. Read moresource§impl MulAssign<u64> for Duration
impl MulAssign<u64> for Duration
source§fn mul_assign(&mut self, rhs: u64)
fn mul_assign(&mut self, rhs: u64)
*=
operation. Read moresource§impl Ord for Duration
impl Ord for Duration
source§impl PartialEq for Duration
impl PartialEq for Duration
source§impl PartialOrd for Duration
impl PartialOrd for Duration
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 moresource§impl SubAssign for Duration
impl SubAssign for Duration
source§fn sub_assign(&mut self, rhs: Self)
fn sub_assign(&mut self, rhs: Self)
-=
operation. Read more