Struct fugit::Instant[][src]

pub struct Instant<T, const NOM: u32, const DENOM: u32> { /* fields omitted */ }
Expand description

Represents an instant in time.

The generic T can either be u32 or u64, and the const generics represent the ratio of the ticks contained within the instant: instant in seconds = NOM / DENOM * ticks

Implementations

Create an Instant from a ticks value.

let _i = Instant::<u32, 1, 1_000>::from_ticks(1);

Extract the ticks from an Instant.

let i = Instant::<u32, 1, 1_000>::from_ticks(234);

assert_eq!(i.ticks(), 234);

Const comparison of Instants.

let i1 = Instant::<u32, 1, 1_000>::from_ticks(1);
let i2 = Instant::<u32, 1, 1_000>::from_ticks(2);

assert_eq!(i1.const_cmp(i2), core::cmp::Ordering::Less);

Duration between since the start of the Instant. This assumes an instant which won’t wrap within the execution of the program.

let i = Instant::<u32, 1, 1_000>::from_ticks(11);

assert_eq!(i.duration_since_epoch().ticks(), 11);

Duration between Instants.

let i1 = Instant::<u32, 1, 1_000>::from_ticks(1);
let i2 = Instant::<u32, 1, 1_000>::from_ticks(2);

assert_eq!(i1.checked_duration_since(i2), None);
assert_eq!(i2.checked_duration_since(i1).unwrap().ticks(), 1);

Subtract a Duration from an Instant while checking for overflow.

let i = Instant::<u32, 1, 1_000>::from_ticks(1);
let d = Duration::<u32, 1, 1_000>::from_ticks(1);

assert_eq!(i.checked_sub_duration(d).unwrap().ticks(), 0);

Add a Duration to an Instant while checking for overflow.

let i = Instant::<u32, 1, 1_000>::from_ticks(1);
let d = Duration::<u32, 1, 1_000>::from_ticks(1);

assert_eq!(i.checked_add_duration(d).unwrap().ticks(), 2);

Create an Instant from a ticks value.

let _i = Instant::<u64, 1, 1_000>::from_ticks(1);

Extract the ticks from an Instant.

let i = Instant::<u64, 1, 1_000>::from_ticks(234);

assert_eq!(i.ticks(), 234);

Const comparison of Instants.

let i1 = Instant::<u64, 1, 1_000>::from_ticks(1);
let i2 = Instant::<u64, 1, 1_000>::from_ticks(2);

assert_eq!(i1.const_cmp(i2), core::cmp::Ordering::Less);

Duration between since the start of the Instant. This assumes an instant which won’t wrap within the execution of the program.

let i = Instant::<u64, 1, 1_000>::from_ticks(11);

assert_eq!(i.duration_since_epoch().ticks(), 11);

Duration between Instants.

let i1 = Instant::<u64, 1, 1_000>::from_ticks(1);
let i2 = Instant::<u64, 1, 1_000>::from_ticks(2);

assert_eq!(i1.checked_duration_since(i2), None);
assert_eq!(i2.checked_duration_since(i1).unwrap().ticks(), 1);

Subtract a Duration from an Instant while checking for overflow.

let i = Instant::<u64, 1, 1_000>::from_ticks(1);
let d = Duration::<u64, 1, 1_000>::from_ticks(1);

assert_eq!(i.checked_sub_duration(d).unwrap().ticks(), 0);

Add a Duration to an Instant while checking for overflow.

let i = Instant::<u64, 1, 1_000>::from_ticks(1);
let d = Duration::<u64, 1, 1_000>::from_ticks(1);

assert_eq!(i.checked_add_duration(d).unwrap().ticks(), 2);

Trait Implementations

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

The resulting type after applying the + operator.

Performs the + operation. Read more

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Formats the value using the given formatter. Read more

Writes the defmt representation of self to fmt.

Writes the defmt representation of self to fmt.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

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

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

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

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

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

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

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

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

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

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

The resulting type after applying the - operator.

Performs the - operation. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.