Skip to main content

RobotClock

Struct RobotClock 

Source
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§

Source§

impl RobotClock

Source

pub fn is_mock(&self) -> bool

Whether time is controlled explicitly by a mock handle.

Source

pub fn new() -> Self

Creates a clock with a local epoch using the host RTC for calibration.

Source

pub fn new_with_rtc( read_rtc_ns: impl Fn() -> u64 + Send + Sync + 'static, sleep_ns: impl Fn(u64) + Send + Sync + 'static, ) -> Self

Calibrates the architecture counter against an application RTC.

Source

pub fn from_ref_time(ref_time_ns: u64) -> Self

Builds a monotonic clock starting at the requested reference time.

Source

pub fn from_ref_time_with_rtc( read_rtc_ns: fn() -> u64, sleep_ns: fn(u64), ref_time_ns: u64, ) -> Self

Builds a clock starting at the requested time using an application RTC.

Source

pub fn from_ref_time_with_origin(ref_time_ns: u64, origin: ClockOrigin) -> Self

Builds a local monotonic clock at provider-selected reference nanoseconds.

Metadata never transforms the timestamp or implies live synchronization.

Source

pub fn from_ref_time_with_rtc_and_origin( read_rtc_ns: fn() -> u64, sleep_ns: fn(u64), ref_time_ns: u64, origin: ClockOrigin, ) -> Self

Builds a clock at a named epoch using application RTC calibration.

The RTC only calibrates elapsed time; origin describes the supplied epoch.

Source

pub fn mock() -> (Self, RobotClockMock)

Builds a clock controlled by a mock, shared by all clones.

Source

pub fn now(&self) -> CuTime

Reads execution time: local elapsed time, or the selected reference epoch.

Source

pub fn origin(&self) -> ClockOrigin

Describes the source and epoch of execution timestamps without converting them.

Reference metadata is published with the execution mapping and shared by clones. Before initial acquisition, the local origin remains in effect. During resynchronization, the previous epoch remains in effect while the execution clock slews. Providers must preserve the epoch across resync. This accessor performs no counter read, allocation, or reference I/O.

use cu29_clock::{ClockEpoch, ClockSource, RobotClock};
let (clock, _) = RobotClock::mock();
assert_eq!(clock.origin().source, ClockSource::Mock);
assert_eq!(clock.origin().epoch, ClockEpoch::Local);
Source

pub fn recent(&self) -> CuTime

Reads the same timeline through the backend’s recent-time operation.

Source

pub fn raw_now(&self) -> CuInstant

Reads undisciplined local counter time in nanoseconds.

Clones share the counter origin and calibration. Independently constructed clocks have their own origins; compare raw readings only within one clock and its clones. Reference capture and elapsed-time measurements use this timeline, which is unaffected by execution-clock synchronization.

use cu29_clock::{CuDuration, RobotClock};

let (clock, control) = RobotClock::mock();
let start = clock.raw_now();
control.increment(CuDuration::from_millis(1));
assert_eq!(clock.raw_now() - start, CuDuration::from_millis(1));
Source

pub fn busy_wait_for(&self, duration: CuDuration)

Spins for a duration measured on this clock’s undisciplined timeline.

Source

pub fn busy_wait_until(&self, time: CuInstant)

Spins until a raw deadline from this clock or one of its clones.

Source

pub fn sync_status(&self) -> Option<SyncStatus>

Current domain, uncertainty and synchronization health.

Available with or without clock-sync. Returns None when synchronization is disabled or no discipline has been published. Without the feature this does not read the counter or require synchronization storage.

use cu29_clock::{RobotClock, sync::SyncStatus};

let (clock, _) = RobotClock::mock();
let quality: Option<SyncStatus> = clock.sync_status();
assert_eq!(quality, None);

Trait Implementations§

Source§

impl Clone for RobotClock

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for RobotClock

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for RobotClock

Available on crate feature std only.

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.

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Converts Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Converts Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Converts &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Converts &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSend for T
where T: Any + Send,

§

fn into_any_send(self: Box<T>) -> Box<dyn Any + Send>

Converts Box<Trait> (where Trait: DowncastSend) to Box<dyn Any + Send>, which can then be downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<A> Is for A
where A: Any,

§

fn is<T>() -> bool
where T: Any,

Checks if the current type “is” another type, using a TypeId equality comparison. This is most useful in the context of generic logic. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> TypeData for T
where T: 'static + Send + Sync + Clone,

§

fn clone_type_data(&self) -> Box<dyn TypeData>

Creates a type-erased clone of this value.