[−][src]Struct embedded_time::Instant
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: Clock> Instant<Clock>
[src][−]
pub fn new(ticks: Clock::T) -> Self
[src][−]
Construct a new Instant from the provided Clock
pub fn checked_duration_since(&self, other: &Self) -> Option<Generic<Clock::T>>
[src][−]
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: &Self) -> Option<Generic<Clock::T>>
[src][−]
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::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: Duration>(self, duration: Dur) -> Option<Self> where
Dur: FixedPoint,
Clock::T: TryFrom<Dur::T> + Div<Output = Clock::T>,
[src][−]
Dur: FixedPoint,
Clock::T: TryFrom<Dur::T> + Div<Output = 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: Duration>(self, duration: Dur) -> Option<Self> where
Dur: FixedPoint,
Clock::T: TryFrom<Dur::T> + Div<Output = Clock::T>,
[src][−]
Dur: FixedPoint,
Clock::T: TryFrom<Dur::T> + Div<Output = 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: Clock, Dur: Duration> Add<Dur> for Instant<Clock> where
Clock::T: TryFrom<Dur::T>,
Dur: FixedPoint,
[src][+]
Clock::T: TryFrom<Dur::T>,
Dur: FixedPoint,
impl<T: TimeInt, Clock: Clock> Add<Instant<Clock>> for Hours<T> where
Clock::T: TryFrom<T>,
[src][+]
Clock::T: TryFrom<T>,
impl<T: TimeInt, Clock: Clock> Add<Instant<Clock>> for Minutes<T> where
Clock::T: TryFrom<T>,
[src][+]
Clock::T: TryFrom<T>,
impl<T: TimeInt, Clock: Clock> Add<Instant<Clock>> for Seconds<T> where
Clock::T: TryFrom<T>,
[src][+]
Clock::T: TryFrom<T>,
impl<T: TimeInt, Clock: Clock> Add<Instant<Clock>> for Milliseconds<T> where
Clock::T: TryFrom<T>,
[src][+]
Clock::T: TryFrom<T>,
impl<T: TimeInt, Clock: Clock> Add<Instant<Clock>> for Microseconds<T> where
Clock::T: TryFrom<T>,
[src][+]
Clock::T: TryFrom<T>,
impl<T: TimeInt, Clock: Clock> Add<Instant<Clock>> for Nanoseconds<T> where
Clock::T: TryFrom<T>,
[src][+]
Clock::T: TryFrom<T>,
impl<Clock: Clock> Clone for Instant<Clock>
[src][+]
impl<Clock: Clock> Copy for Instant<Clock>
[src]
impl<Clock: Debug + Clock> Debug for Instant<Clock> where
Clock::T: Debug,
[src][+]
Clock::T: Debug,
impl<Clock: Clock> Eq for Instant<Clock>
[src]
impl<Clock: Clock> Hash for Instant<Clock>
[src][+]
impl<Clock> Ord for Instant<Clock> where
Clock: Clock,
Clock::T: Div<Output = Clock::T>,
[src][+]
Clock: Clock,
Clock::T: Div<Output = Clock::T>,
impl<Clock: Clock> PartialEq<Instant<Clock>> for Instant<Clock>
[src][+]
impl<Clock: Clock> PartialOrd<Instant<Clock>> for Instant<Clock>
[src][+]
impl<Clock: Clock, Dur: Duration> Sub<Dur> for Instant<Clock> where
Clock::T: TryFrom<Dur::T>,
Dur: FixedPoint,
[src][+]
Clock::T: TryFrom<Dur::T>,
Dur: FixedPoint,
impl<Clock: Clock> Sub<Instant<Clock>> for Instant<Clock>
[src][+]
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,
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>,
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src][+]
U: TryFrom<T>,