[−][src]Struct embedded_time::instant::Instant
Represents an instant of time relative to a specific clock
Example
Create an Instant
that is 23 * SomeClock::PERIOD
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::Rep) -> Self
[src]
pub fn duration_since<Dur>(&self, other: &Self) -> Option<Dur> where
Dur: Duration,
Dur::Rep: TryFrom<Clock::Rep>,
[src]
Dur: Duration,
Dur::Rep: TryFrom<Clock::Rep>,
Calculates the difference between two Instance
s resulting in a Duration
Examples
struct Clock; impl embedded_time::Clock for Clock { type Rep = i32; const PERIOD: Period = Period::new_raw(1, 1_000); // ... } let diff: Option<Milliseconds<_>> = Instant::<Clock>::new(5).duration_since(&Instant::<Clock>::new(3)); assert_eq!(diff, Some(Milliseconds(2_i32))); let diff: Option<Microseconds<i64>> = Instant::<Clock>::new(5).duration_since(&Instant::<Clock>::new(3)); assert_eq!(diff, Some(Microseconds(2_000_i64))); let diff: Option<Microseconds<i64>> = Instant::<Clock>::new(i32::MIN).duration_since(&Instant::<Clock>::new(i32::MAX)); assert_eq!(diff, Some(Microseconds(1_000_i64))); let diff: Option<Seconds<i64>> = Instant::<Clock>::new(1_000).duration_since(&Instant::<Clock>::new(-1_000)); assert_eq!(diff, Some(Seconds(2_i64)));
pub fn elapsed_since_epoch<Dur>(&self) -> Option<Dur> where
Dur: Duration,
Dur::Rep: TryFrom<Clock::Rep>,
Clock::Rep: From<i32>,
[src]
Dur: Duration,
Dur::Rep: TryFrom<Clock::Rep>,
Clock::Rep: From<i32>,
Trait Implementations
impl<Clock, Dur> Add<Dur> for Instant<Clock> where
Clock: Clock,
Clock::Rep: TryFrom<Dur::Rep>,
Dur: Duration,
[src]
Clock: Clock,
Clock::Rep: TryFrom<Dur::Rep>,
Dur: Duration,
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, i32::MAX
of seconds
cannot be converted to the clock precision of milliseconds with i32 storage.
struct Clock; impl embedded_time::Clock for Clock { type Rep = i32; const PERIOD: Period = Period::new_raw(1, 1_000); // ... } Instant::<Clock>::new(1) + Seconds(i32::MAX);
See also: impl Add for Duration
Examples
struct Clock; impl embedded_time::Clock for Clock { type Rep = i32; const PERIOD: Period = Period::new_raw(1, 1_000); // ... } assert_eq!(Instant::<Clock>::new(1) + Seconds(3), Instant::<Clock>::new(3_001)); assert_eq!(Instant::<Clock>::new(-1) + Milliseconds(5_123), Instant::<Clock>::new(5_122)); assert_eq!(Instant::<Clock>::new(1) + Milliseconds(700), Instant::<Clock>::new(701)); assert_eq!(Instant::<Clock>::new(1_i32) + Milliseconds(700_i64), Instant::<Clock>::new(701_i32));
impl<Clock> Clone for Instant<Clock> where
Clock: Clock,
[src]
Clock: Clock,
fn clone(&self) -> Self
[src]
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> Debug for Instant<Clock> where
Clock: Clock,
Clock::Rep: Debug,
[src]
Clock: Clock,
Clock::Rep: Debug,
impl<Clock> Eq for Instant<Clock> where
Clock: Clock,
[src]
Clock: Clock,
impl<Clock> Ord for Instant<Clock> where
Clock: Clock,
[src]
Clock: Clock,
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> PartialEq<Instant<Clock>> for Instant<Clock> where
Clock: Clock,
[src]
Clock: Clock,
impl<Clock> PartialOrd<Instant<Clock>> for Instant<Clock> where
Clock: Clock,
[src]
Clock: Clock,
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 = i32; const PERIOD: Period = Period::new_raw(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(i32::MAX) < Instant::<Clock>::new(i32::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, Dur> Sub<Dur> for Instant<Clock> where
Clock: Clock,
Clock::Rep: TryFrom<Dur::Rep>,
Dur: Duration,
[src]
Clock: Clock,
Clock::Rep: TryFrom<Dur::Rep>,
Dur: Duration,
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, i32::MAX
of seconds
cannot be converted to the clock precision of milliseconds with i32 storage.
struct Clock; impl embedded_time::Clock for Clock { type Rep = i32; const PERIOD: Period = Period::new_raw(1, 1_000); // ... } Instant::<Clock>::new(1) - Seconds(i32::MAX);
See also impl Sub for Duration
Examples
struct Clock; impl embedded_time::Clock for Clock { type Rep = i32; const PERIOD: Period = Period::new_raw(1, 1_000); // ... } assert_eq!(Instant::<Clock>::new(1) - Seconds(3), Instant::<Clock>::new(-2_999)); assert_eq!(Instant::<Clock>::new(-1) - Milliseconds(5_123), Instant::<Clock>::new(-5_124)); assert_eq!(Instant::<Clock>::new(800) - Milliseconds(700), Instant::<Clock>::new(100)); assert_eq!(Instant::<Clock>::new(5_000_i32) - Milliseconds(700_i64), Instant::<Clock>::new(4_300_i32));
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>,