[][src]Struct dw1000::time::Instant

#[repr(C)]pub struct Instant(_);

Represents an instant in time

You can get the current DW1000 system time by calling DW1000::sys_time.

Internally uses the same 40-bit timestamps that the DW1000 uses.

Methods

impl Instant[src]

pub fn new(value: u64) -> Option<Self>[src]

Creates a new instance of Instant

The given value must fit in a 40-bit timestamp, so: 0 <= value <= 2^40 - 1

Returns Some(...), if value is within the valid range, None if it isn't.

Example

use dw1000::time::{
    TIME_MAX,
    Instant,
};

let valid_instant   = Instant::new(TIME_MAX);
let invalid_instant = Instant::new(TIME_MAX + 1);

assert!(valid_instant.is_some());
assert!(invalid_instant.is_none());

pub fn value(&self) -> u64[src]

Returns the raw 40-bit timestamp

The returned value is guaranteed to be in the following range: 0 <= value <= 2^40 - 1

pub fn duration_since(&self, earlier: Instant) -> Duration[src]

Returns the amount of time passed between the two Instants

Assumes that &self represents a later time than the argument earlier. Please make sure that this is the case, as this method has no way of knowing (DW1000 timestamps can overflow, so comparing the numerical value of the timestamp doesn't tell anything about order).

Example

use dw1000::time::{
    TIME_MAX,
    Instant,
};

// `unwrap`ing here is okay, since we're passing constants that we know
// are in the valid range.
let instant_1 = Instant::new(TIME_MAX - 50).unwrap();
let instant_2 = Instant::new(TIME_MAX).unwrap();
let instant_3 = Instant::new(49).unwrap();

// Works as expected, if the later timestamp is larger than the earlier
// one.
let duration = instant_2.duration_since(instant_1);
assert_eq!(duration.value(), 50);

// Still works as expected, if the later timestamp is the numerically
// smaller value.
let duration = instant_3.duration_since(instant_2);
assert_eq!(duration.value(), 50);

Trait Implementations

impl Add<Duration> for Instant[src]

type Output = Instant

The resulting type after applying the + operator.

impl Clone for Instant[src]

impl Copy for Instant[src]

impl Debug for Instant[src]

impl<'de> Deserialize<'de> for Instant[src]

impl Serialize for Instant[src]

Auto Trait Implementations

impl Send for Instant

impl Sync for Instant

impl Unpin for Instant

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> DeserializeOwned for T where
    T: Deserialize<'de>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.