Struct RobotClock
pub struct RobotClock { /* private fields */ }Expand description
A running Robot clock. The clock is a monotonic clock that starts at an arbitrary reference time. It is clone resilient, ie a clone will be the same clock, even when mocked.
Implementations§
§impl RobotClock
impl RobotClock
pub fn new() -> RobotClock
pub fn new() -> RobotClock
Creates a RobotClock using now as its reference time. It will start at 0ns incrementing monotonically. This uses the std System Time as a reference clock.
pub fn new_with_rtc(
read_rtc_ns: impl Fn() -> u64 + Send + Sync + 'static,
sleep_ns: impl Fn(u64) + Send + Sync + 'static,
) -> RobotClock
pub fn new_with_rtc( read_rtc_ns: impl Fn() -> u64 + Send + Sync + 'static, sleep_ns: impl Fn(u64) + Send + Sync + 'static, ) -> RobotClock
Builds a RobotClock using a reference RTC clock to calibrate with. This is mandatory to use with the no-std platforms as we have no idea where to find a reference clock.
pub fn from_ref_time(ref_time_ns: u64) -> RobotClock
pub fn from_ref_time(ref_time_ns: u64) -> RobotClock
Builds a monotonic clock starting at the given reference time.
pub fn from_ref_time_with_rtc(
read_rtc_ns: fn() -> u64,
sleep_ns: fn(u64),
ref_time_ns: u64,
) -> RobotClock
pub fn from_ref_time_with_rtc( read_rtc_ns: fn() -> u64, sleep_ns: fn(u64), ref_time_ns: u64, ) -> RobotClock
Overrides the RTC with a custom implementation, should be the same as the new_with_rtc.
pub fn mock() -> (RobotClock, RobotClockMock)
pub fn mock() -> (RobotClock, RobotClockMock)
Build a fake clock with a reference time of 0. The RobotMock interface enables you to control all the clones of the clock given.
pub fn now(&self) -> CuDuration
pub fn now(&self) -> CuDuration
Now returns the time that passed since the reference time, usually the start time. It is a monotonically increasing value.
pub fn recent(&self) -> CuDuration
pub fn recent(&self) -> CuDuration
A less precise but quicker time
Trait Implementations§
§impl Clone for RobotClock
impl Clone for RobotClock
§fn clone(&self) -> RobotClock
fn clone(&self) -> RobotClock
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more§impl Debug for RobotClock
impl Debug for RobotClock
§impl Default for RobotClock
We cannot build a default RobotClock on no-std because we don’t know how to find a reference clock.
Use RobotClock::new_with_rtc instead on no-std.
impl Default for RobotClock
We cannot build a default RobotClock on no-std because we don’t know how to find a reference clock. Use RobotClock::new_with_rtc instead on no-std.
§fn default() -> RobotClock
fn default() -> RobotClock
Auto Trait Implementations§
impl Freeze for RobotClock
impl RefUnwindSafe for RobotClock
impl Send for RobotClock
impl Sync for RobotClock
impl Unpin for RobotClock
impl UnwindSafe for RobotClock
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more