Struct fugit::Instant [−][src]
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
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 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