Struct rtic_monotonic::Instant [−][src]
Represents an instant of time relative to a specific Clock
Example
Typically an Instant
will be obtained from a Clock
let some_clock = SomeClock; let some_instant = some_clock.try_now().unwrap();
However, an Instant
can also be constructed directly. In this case the constructed Instant
is 23 * SomeClock::SCALING_FACTOR
seconds since the clock’s epoch
Instant::<SomeClock>::new(23);
Implementations
impl<Clock> Instant<Clock> where
Clock: Clock,
[src]
Clock: Clock,
pub fn new(ticks: <Clock as Clock>::T) -> Instant<Clock>
[src]
Construct a new Instant from the provided Clock
pub fn checked_duration_since(
&self,
other: &Instant<Clock>
) -> Option<Generic<<Clock as Clock>::T>>
[src]
&self,
other: &Instant<Clock>
) -> Option<Generic<<Clock as Clock>::T>>
Returns the amount of time elapsed from another instant to this one as a
duration::Generic
or None
if the other instant is later than
this one.
Examples
struct Clock; impl embedded_time::Clock for Clock { type T = u32; const SCALING_FACTOR: Fraction = Fraction::new(1, 1_000); // ... } // Given `instant1` at 3 `Clock` ticks // Given `instant2` at 5 `Clock` ticks let generic_duration = instant2.checked_duration_since(&instant1).unwrap(); // Convert into a _named_ `Duration` let microseconds: Microseconds<u32> = generic_duration.try_into().unwrap(); assert_eq!(microseconds, Microseconds(2_000_u32));
pub fn checked_duration_until(
&self,
other: &Instant<Clock>
) -> Option<Generic<<Clock as Clock>::T>>
[src]
&self,
other: &Instant<Clock>
) -> Option<Generic<<Clock as Clock>::T>>
Returns the amount of time elapsed from self until that given instant
duration::Generic
or None
if the other instant is later than
this one.
Examples
struct Clock; impl embedded_time::Clock for Clock { type T = u32; const SCALING_FACTOR: Fraction = Fraction::new(1, 1_000); // ... } // Given `instant1` at 3 `Clock` ticks // Given `instant2` at 5 `Clock` ticks let generic_duration = instant1.checked_duration_until(&instant2).unwrap(); // Convert into a _named_ `Duration` let microseconds: Microseconds<u32> = generic_duration.try_into().unwrap(); assert_eq!(microseconds, Microseconds(2_000_u32));
pub fn duration_since_epoch(&self) -> Generic<<Clock as Clock>::T>
[src]
Returns the Duration
(in the provided units) since the beginning of time (the
Clock
’s 0)
If it is a wrapping clock, the result is meaningless.
pub fn checked_add<Dur>(self, duration: Dur) -> Option<Instant<Clock>> where
Dur: Duration + FixedPoint,
<Clock as Clock>::T: TryFrom<<Dur as FixedPoint>::T>,
<Clock as Clock>::T: Div<<Clock as Clock>::T>,
<<Clock as Clock>::T as Div<<Clock as Clock>::T>>::Output == <Clock as Clock>::T,
[src]
Dur: Duration + FixedPoint,
<Clock as Clock>::T: TryFrom<<Dur as FixedPoint>::T>,
<Clock as Clock>::T: Div<<Clock as Clock>::T>,
<<Clock as Clock>::T as Div<<Clock as Clock>::T>>::Output == <Clock as Clock>::T,
This Instant
+ Duration
= later (future) Instant
Returns None
if the Duration
is too large
Examples
struct Clock; impl embedded_time::Clock for Clock { type T = u32; const SCALING_FACTOR: Fraction = Fraction::new(1, 1_000); // ... } assert_eq!( Instant::<Clock>::new(0).checked_add(Milliseconds(u32::MAX/2)), Some(Instant::<Clock>::new(u32::MAX/2)) ); assert_eq!( Instant::<Clock>::new(0).checked_add(Milliseconds(u32::MAX/2 + 1)), None );
pub fn checked_sub<Dur>(self, duration: Dur) -> Option<Instant<Clock>> where
Dur: Duration + FixedPoint,
<Clock as Clock>::T: TryFrom<<Dur as FixedPoint>::T>,
<Clock as Clock>::T: Div<<Clock as Clock>::T>,
<<Clock as Clock>::T as Div<<Clock as Clock>::T>>::Output == <Clock as Clock>::T,
[src]
Dur: Duration + FixedPoint,
<Clock as Clock>::T: TryFrom<<Dur as FixedPoint>::T>,
<Clock as Clock>::T: Div<<Clock as Clock>::T>,
<<Clock as Clock>::T as Div<<Clock as Clock>::T>>::Output == <Clock as Clock>::T,
This Instant
- Duration
= earlier Instant
Returns None
if the Duration
is too large
Examples
struct Clock; impl embedded_time::Clock for Clock { type T = u32; const SCALING_FACTOR: Fraction = Fraction::new(1, 1_000); // ... } assert_eq!(Instant::<Clock>::new(u32::MAX).checked_sub(Milliseconds(u32::MAX/2)), Some(Instant::<Clock>::new(u32::MAX - u32::MAX/2))); assert_eq!(Instant::<Clock>::new(u32::MAX).checked_sub(Milliseconds(u32::MAX/2 + 1)), None);
Trait Implementations
impl<Clock, Dur> Add<Dur> for Instant<Clock> where
Clock: Clock,
Dur: Duration + FixedPoint,
<Clock as Clock>::T: TryFrom<<Dur as FixedPoint>::T>,
[src]
Clock: Clock,
Dur: Duration + FixedPoint,
<Clock as Clock>::T: TryFrom<<Dur as FixedPoint>::T>,
type Output = Instant<Clock>
The resulting type after applying the +
operator.
pub fn add(self, rhs: Dur) -> <Instant<Clock> as Add<Dur>>::Output
[src]
Add a Duration
to an Instant
resulting in a new, later Instant
Examples
struct Clock; impl embedded_time::Clock for Clock { type T = u32; const SCALING_FACTOR: Fraction = Fraction::new(1, 1_000); // ... } assert_eq!(Instant::<Clock>::new(1) + Seconds(3_u32), Instant::<Clock>::new(3_001)); assert_eq!(Instant::<Clock>::new(1) + Milliseconds(700_u32), Instant::<Clock>::new(701)); assert_eq!(Instant::<Clock>::new(1) + Milliseconds(700_u64), Instant::<Clock>::new(701)); // maximum duration allowed assert_eq!(Instant::<Clock>::new(0) + Milliseconds(i32::MAX as u32), Instant::<Clock>::new(u32::MAX/2));
Panics
Virtually the same reason the integer operation would panic. Namely, if the result overflows the type. Specifically, if the duration is more than half the wrap-around period of the clock.
struct Clock; impl embedded_time::Clock for Clock { type T = u32; const SCALING_FACTOR: Fraction = Fraction::new(1, 1_000); // ... } Instant::<Clock>::new(0) + Milliseconds(u32::MAX/2 + 1);
impl<Clock> Clone for Instant<Clock> where
Clock: Clock,
[src]
Clock: Clock,
pub fn clone(&self) -> Instant<Clock>
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<Clock> Copy for Instant<Clock> where
Clock: Clock,
[src]
Clock: Clock,
impl<Clock> Debug for Instant<Clock> where
Clock: Clock + Debug,
<Clock as Clock>::T: Debug,
[src]
Clock: Clock + Debug,
<Clock as Clock>::T: Debug,
impl<Clock> Eq for Instant<Clock> where
Clock: Clock,
[src]
Clock: Clock,
impl<Clock> Hash for Instant<Clock> where
Clock: Clock,
[src]
Clock: Clock,
pub fn hash<H>(&self, state: &mut H) where
H: Hasher,
[src]
H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<Clock> Ord for Instant<Clock> where
Clock: Clock,
<Clock as Clock>::T: Div<<Clock as Clock>::T>,
<<Clock as Clock>::T as Div<<Clock as Clock>::T>>::Output == <Clock as Clock>::T,
[src]
Clock: Clock,
<Clock as Clock>::T: Div<<Clock as Clock>::T>,
<<Clock as Clock>::T as Div<<Clock as Clock>::T>>::Output == <Clock as Clock>::T,
pub fn cmp(&self, other: &Instant<Clock>) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl<Clock> PartialEq<Instant<Clock>> for Instant<Clock> where
Clock: Clock,
[src]
Clock: Clock,
pub fn eq(&self, other: &Instant<Clock>) -> bool
[src]
#[must_use]pub fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<Clock> PartialOrd<Instant<Clock>> for Instant<Clock> where
Clock: Clock,
[src]
Clock: Clock,
pub fn partial_cmp(&self, other: &Instant<Clock>) -> Option<Ordering>
[src]
Calculates the difference between two Instant
s resulting in a Duration
struct Clock; impl embedded_time::Clock for Clock { type T = u32; const SCALING_FACTOR: Fraction = Fraction::new(1, 1_000); // ... } assert!(Instant::<Clock>::new(5) > Instant::<Clock>::new(3)); assert!(Instant::<Clock>::new(5) == Instant::<Clock>::new(5)); assert!(Instant::<Clock>::new(u32::MAX) < Instant::<Clock>::new(u32::MIN));
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<Clock, Dur> Sub<Dur> for Instant<Clock> where
Clock: Clock,
Dur: Duration + FixedPoint,
<Clock as Clock>::T: TryFrom<<Dur as FixedPoint>::T>,
[src]
Clock: Clock,
Dur: Duration + FixedPoint,
<Clock as Clock>::T: TryFrom<<Dur as FixedPoint>::T>,
type Output = Instant<Clock>
The resulting type after applying the -
operator.
pub fn sub(self, rhs: Dur) -> <Instant<Clock> as Sub<Dur>>::Output
[src]
Subtract a Duration
from an Instant
resulting in a new, earlier Instant
Examples
struct Clock; impl embedded_time::Clock for Clock { type T = u32; const SCALING_FACTOR: Fraction = Fraction::new(1, 1_000); // ... } assert_eq!(Instant::<Clock>::new(5_001) - Seconds(3_u32), Instant::<Clock>::new(2_001)); assert_eq!(Instant::<Clock>::new(800) - Milliseconds(700_u32), Instant::<Clock>::new(100)); assert_eq!(Instant::<Clock>::new(5_000) - Milliseconds(700_u64), Instant::<Clock>::new(4_300)); // maximum duration allowed assert_eq!(Instant::<Clock>::new(u32::MAX) - Milliseconds(i32::MAX as u32), Instant::<Clock>::new(u32::MAX/2 + 1));
Panics
Virtually the same reason the integer operation would panic. Namely, if the result overflows the type. Specifically, if the duration is more than half the wrap-around period of the clock.
struct Clock; impl embedded_time::Clock for Clock { type T = u32; const SCALING_FACTOR: Fraction = Fraction::new(1, 1_000); // ... } Instant::<Clock>::new(u32::MAX) - Milliseconds(u32::MAX/2 + 1);
Auto Trait Implementations
impl<Clock> Send for Instant<Clock> where
<Clock as Clock>::T: Send,
<Clock as Clock>::T: Send,
impl<Clock> Sync for Instant<Clock> where
<Clock as Clock>::T: Sync,
<Clock as Clock>::T: Sync,
impl<Clock> Unpin for Instant<Clock> where
<Clock as Clock>::T: Unpin,
<Clock as Clock>::T: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,