Struct femtos::Duration

source ·
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

source

pub const ZERO: Self = _

A duration of zero (0) time

source

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

source

pub const FEMTOS_PER_SEC: Femtos = 1_000_000_000_000_000u128

The number of femtoseconds in 1 second as Femtos

source

pub const FEMTOS_PER_MILLISEC: Femtos = 1_000_000_000_000u128

The number of femtoseconds in 1 millisecond as Femtos

source

pub const FEMTOS_PER_MICROSEC: Femtos = 1_000_000_000u128

The number of femtoseconds in 1 microsecond as Femtos

source

pub const FEMTOS_PER_NANOSEC: Femtos = 1_000_000u128

The number of femtoseconds in 1 nanosecond as Femtos

source

pub const FEMTOS_PER_PICOSEC: Femtos = 1_000u128

The number of femtoseconds in 1 picosecond as Femtos

source

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());
source

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());
source

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());
source

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());
source

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());
source

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());
source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

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);
source

pub const fn checked_sub(self, rhs: Self) -> Option<Self>

Checked Duration subtraction. Computes self - rhs, returning None if an overflow occured.

§Examples
use femtos::Duration;

assert_eq!(Duration::from_secs(1).checked_sub(Duration::from_secs(1)), Some(Duration::ZERO));
assert_eq!(Duration::from_femtos(1).checked_sub(Duration::from_femtos(2)), None);

Trait Implementations§

source§

impl Add<Duration> for Instant

§

type Output = Instant

The resulting type after applying the + operator.
source§

fn add(self, rhs: Duration) -> Self::Output

Performs the + operation. Read more
source§

impl Add for Duration

§

type Output = Duration

The resulting type after applying the + operator.
source§

fn add(self, rhs: Self) -> Self::Output

Performs the + operation. Read more
source§

impl AddAssign<Duration> for Instant

source§

fn add_assign(&mut self, rhs: Duration)

Performs the += operation. Read more
source§

impl AddAssign for Duration

source§

fn add_assign(&mut self, rhs: Self)

Performs the += operation. Read more
source§

impl Clone for Duration

source§

fn clone(&self) -> Duration

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Debug for Duration

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
source§

impl Div<u32> for Duration

§

type Output = Duration

The resulting type after applying the / operator.
source§

fn div(self, rhs: u32) -> Self::Output

Performs the / operation. Read more
source§

impl Div<u64> for Duration

§

type Output = Duration

The resulting type after applying the / operator.
source§

fn div(self, rhs: u64) -> Self::Output

Performs the / operation. Read more
source§

impl Div for Duration

§

type Output = u64

The resulting type after applying the / operator.
source§

fn div(self, rhs: Duration) -> Self::Output

Performs the / operation. Read more
source§

impl DivAssign<u32> for Duration

source§

fn div_assign(&mut self, rhs: u32)

Performs the /= operation. Read more
source§

impl DivAssign<u64> for Duration

source§

fn div_assign(&mut self, rhs: u64)

Performs the /= operation. Read more
source§

impl From<Duration> for Duration

source§

fn from(value: Duration) -> Self

Converts to this type from the input type.
source§

impl From<Duration> for Duration

source§

fn from(value: Duration) -> Self

Converts to this type from the input type.
source§

impl Mul<u32> for Duration

§

type Output = Duration

The resulting type after applying the * operator.
source§

fn mul(self, rhs: u32) -> Self::Output

Performs the * operation. Read more
source§

impl Mul<u64> for Duration

§

type Output = Duration

The resulting type after applying the * operator.
source§

fn mul(self, rhs: u64) -> Self::Output

Performs the * operation. Read more
source§

impl MulAssign<u32> for Duration

source§

fn mul_assign(&mut self, rhs: u32)

Performs the *= operation. Read more
source§

impl MulAssign<u64> for Duration

source§

fn mul_assign(&mut self, rhs: u64)

Performs the *= operation. Read more
source§

impl Ord for Duration

source§

fn cmp(&self, other: &Duration) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized + PartialOrd,

Restrict a value to a certain interval. Read more
source§

impl PartialEq for Duration

source§

fn eq(&self, other: &Duration) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl PartialOrd for Duration

source§

fn partial_cmp(&self, other: &Duration) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Sub for Duration

§

type Output = Duration

The resulting type after applying the - operator.
source§

fn sub(self, rhs: Self) -> Self::Output

Performs the - operation. Read more
source§

impl SubAssign for Duration

source§

fn sub_assign(&mut self, rhs: Self)

Performs the -= operation. Read more
source§

impl Copy for Duration

source§

impl Eq for Duration

source§

impl StructuralPartialEq for Duration

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.