[−][src]Struct dw1000::time::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 Instant
s
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 Clone for Instant
[src]
fn clone(&self) -> Instant
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
impl Copy for Instant
[src]
impl Debug for Instant
[src]
impl Add<Duration> for Instant
[src]
type Output = Instant
The resulting type after applying the +
operator.
fn add(self, rhs: Duration) -> Self::Output
[src]
impl Serialize for Instant
[src]
fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error> where
__S: Serializer,
[src]
__S: Serializer,
impl<'de> Deserialize<'de> for Instant
[src]
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error> where
__D: Deserializer<'de>,
[src]
__D: Deserializer<'de>,
Auto Trait Implementations
Blanket Implementations
impl<T> From for T
[src]
impl<T, U> TryFrom 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 for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> DeserializeOwned for T where
T: Deserialize<'de>,
[src]
T: Deserialize<'de>,