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
impl RobotClock
Sourcepub fn new_with_rtc(
read_rtc_ns: impl Fn() -> u64 + Send + Sync + 'static,
sleep_ns: impl Fn(u64) + Send + Sync + 'static,
) -> Self
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.
Sourcepub fn from_ref_time(ref_time_ns: u64) -> Self
pub fn from_ref_time(ref_time_ns: u64) -> Self
Builds a monotonic clock starting at the requested reference time.
Sourcepub fn from_ref_time_with_rtc(
read_rtc_ns: fn() -> u64,
sleep_ns: fn(u64),
ref_time_ns: u64,
) -> Self
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.
Sourcepub fn from_ref_time_with_origin(ref_time_ns: u64, origin: ClockOrigin) -> Self
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.
Sourcepub fn from_ref_time_with_rtc_and_origin(
read_rtc_ns: fn() -> u64,
sleep_ns: fn(u64),
ref_time_ns: u64,
origin: ClockOrigin,
) -> Self
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.
Sourcepub fn mock() -> (Self, RobotClockMock)
pub fn mock() -> (Self, RobotClockMock)
Builds a clock controlled by a mock, shared by all clones.
Sourcepub fn now(&self) -> CuTime
pub fn now(&self) -> CuTime
Reads execution time: local elapsed time, or the selected reference epoch.
Sourcepub fn origin(&self) -> ClockOrigin
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);Sourcepub fn recent(&self) -> CuTime
pub fn recent(&self) -> CuTime
Reads the same timeline through the backend’s recent-time operation.
Sourcepub fn raw_now(&self) -> CuInstant
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));Sourcepub fn busy_wait_for(&self, duration: CuDuration)
pub fn busy_wait_for(&self, duration: CuDuration)
Spins for a duration measured on this clock’s undisciplined timeline.
Sourcepub fn busy_wait_until(&self, time: CuInstant)
pub fn busy_wait_until(&self, time: CuInstant)
Spins until a raw deadline from this clock or one of its clones.
Sourcepub fn sync_status(&self) -> Option<SyncStatus>
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
impl Clone for RobotClock
Source§impl Debug for RobotClock
impl Debug for 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 UnsafeUnpin 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,
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.