[−][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.now().unwrap();
However, an Instant
can also be constructed directly. In this case the constructed Instant
is 23 * SomeClock::PERIOD
seconds since the clock's epoch
Instant::<SomeClock>::new(23);
Implementations
impl<Clock: Clock> Instant<Clock>
[src]
pub fn new(ticks: Clock::Rep) -> Self
[src]
Construct a new Instant with ticks of the provided Clock
.
pub fn duration_since<Dur: Duration>(&self, other: &Self) -> Result<Dur, ()> where
Dur::Rep: TryFrom<Clock::Rep>,
[src]
Dur::Rep: TryFrom<Clock::Rep>,
Returns the Duration
since the given Instant
Errors
()
: RHS is a futureInstant
()
: problem coverting to desiredDuration
Examples
struct Clock; impl embedded_time::Clock for Clock { type Rep = u32; const PERIOD: Period = <Period>::new(1, 1_000); // ... } assert_eq!(Instant::<Clock>::new(5).duration_since::<Microseconds<u64>>(&Instant::<Clock>::new(3)), Ok(Microseconds(2_000_u64))); assert_eq!(Instant::<Clock>::new(3).duration_since::<Microseconds<u64>>(&Instant::<Clock>::new(5)), Err(()));
pub fn duration_until<Dur: Duration>(&self, other: &Self) -> Result<Dur, ()> where
Dur::Rep: TryFrom<Clock::Rep>,
[src]
Dur::Rep: TryFrom<Clock::Rep>,
Returns the Duration
until the given Instant
Errors
()
: RHS is a pastInstant
()
: problem coverting to desiredDuration
Examples
struct Clock; impl embedded_time::Clock for Clock { type Rep = u32; const PERIOD: Period =<Period>::new(1, 1_000); // ... } assert_eq!(Instant::<Clock>::new(5).duration_until::<Microseconds<u64>>(&Instant::<Clock>::new(7)), Ok(Microseconds(2_000_u64))); assert_eq!(Instant::<Clock>::new(7).duration_until::<Microseconds<u64>>(&Instant::<Clock>::new(5)), Err(()));
pub fn duration_since_epoch<Dur: Duration>(&self) -> Result<Dur, ()> where
Dur::Rep: TryFrom<Clock::Rep>,
Clock::Rep: TryFrom<Dur::Rep>,
[src]
Dur::Rep: TryFrom<Clock::Rep>,
Clock::Rep: TryFrom<Dur::Rep>,
Trait Implementations
impl<Clock: Clock, Dur: Duration> Add<Dur> for Instant<Clock> where
Clock::Rep: TryFrom<Dur::Rep>,
[src]
Clock::Rep: TryFrom<Dur::Rep>,
type Output = Self
The resulting type after applying the +
operator.
fn add(self, rhs: Dur) -> Self::Output
[src]
Add a duration to an instant resulting in a new, later instance
Panics
If Duration::into_ticks()
returns None
. In this case, u32::MAX
of seconds
cannot be converted to the clock precision of milliseconds with u32 storage.
struct Clock; impl embedded_time::Clock for Clock { type Rep = u32; const PERIOD: Period =<Period>::new(1, 1_000); // ... } Instant::<Clock>::new(1) + Seconds(u32::MAX);
If the the Duration
is greater than the signed Clock::Rep max value which would cause
the result to (logically) overflow
struct Clock; impl embedded_time::Clock for Clock { type Rep = u32; const PERIOD: Period =<Period>::new(1, 1_000); // ... } let _ = Instant::<Clock>::new(0) + Milliseconds(i32::MAX as u32 + 1);
See also impl Sub for Duration
Examples
struct Clock; impl embedded_time::Clock for Clock { type Rep = u32; const PERIOD: Period =<Period>::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));
impl<Clock: Clock> Clone for Instant<Clock>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<Clock: Clock> Copy for Instant<Clock>
[src]
impl<Clock: Debug + Clock> Debug for Instant<Clock> where
Clock::Rep: Debug,
[src]
Clock::Rep: Debug,
impl<Clock: Clock> Eq for Instant<Clock>
[src]
impl<Clock: Clock> Ord for Instant<Clock>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
#[must_use]fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<Clock: Clock> PartialEq<Instant<Clock>> for Instant<Clock>
[src]
impl<Clock: Clock> PartialOrd<Instant<Clock>> for Instant<Clock>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
Calculates the difference between two Instance
s resulting in a Duration
Examples
struct Clock; impl embedded_time::Clock for Clock { type Rep = u32; const PERIOD: Period =<Period>::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]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<Clock: Clock, Dur: Duration> Sub<Dur> for Instant<Clock> where
Clock::Rep: TryFrom<Dur::Rep>,
[src]
Clock::Rep: TryFrom<Dur::Rep>,
type Output = Self
The resulting type after applying the -
operator.
fn sub(self, rhs: Dur) -> Self::Output
[src]
Subtract a duration from an instant resulting in a new, earlier instance
Panics
If Duration::into_ticks()
returns None
. In this case, u32::MAX
of seconds
cannot be converted to the clock precision of milliseconds with u32 storage.
struct Clock; impl embedded_time::Clock for Clock { type Rep = u32; const PERIOD: Period =<Period>::new(1, 1_000); // ... } Instant::<Clock>::new(1) - Seconds(u32::MAX);
If the the Duration
is greater than the signed Clock::Rep max value which would cause
the result to (logically) underflow
struct Clock; impl embedded_time::Clock for Clock { type Rep = u32; const PERIOD: Period = <Period>::new(1, 1_000); // ... } let _ = Instant::<Clock>::new(u32::MAX) - Milliseconds(i32::MAX as u32 + 1);
See also impl Sub for Duration
Examples
struct Clock; impl embedded_time::Clock for Clock { type Rep = u32; const PERIOD: Period =<Period>::new(1, 1_000); // ... } 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));
Auto Trait Implementations
impl<Clock> Send for Instant<Clock> where
<Clock as Clock>::Rep: Send,
<Clock as Clock>::Rep: Send,
impl<Clock> Sync for Instant<Clock> where
<Clock as Clock>::Rep: Sync,
<Clock as Clock>::Rep: Sync,
impl<Clock> Unpin for Instant<Clock> where
<Clock as Clock>::Rep: Unpin,
<Clock as Clock>::Rep: 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,
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.
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>,