pub struct ClockApi<'a> { /* private fields */ }Expand description
Provides a user-facing facade over clock operations.
Calls delegate to either a borrowed Clock or a set of operation handlers.
Panics from supplied operation handlers propagate to the caller.
Implementations§
Source§impl<'a> ClockApi<'a>
impl<'a> ClockApi<'a>
Sourcepub fn timestamp_ns(&self) -> UnixNanos
pub fn timestamp_ns(&self) -> UnixNanos
Returns the current UNIX timestamp in nanoseconds.
§Panics
With native backing, panics if the clock is already mutably borrowed.
Sourcepub fn timestamp_us(&self) -> u64
pub fn timestamp_us(&self) -> u64
Returns the current UNIX timestamp in microseconds.
§Panics
With native backing, panics if the clock is already mutably borrowed.
Sourcepub fn timestamp_ms(&self) -> u64
pub fn timestamp_ms(&self) -> u64
Returns the current UNIX timestamp in milliseconds.
§Panics
With native backing, panics if the clock is already mutably borrowed.
Sourcepub fn timestamp(&self) -> f64
pub fn timestamp(&self) -> f64
Returns the current UNIX timestamp in seconds.
§Panics
With native backing, panics if the clock is already mutably borrowed.
Sourcepub fn utc_now(&self) -> Timestamp
pub fn utc_now(&self) -> Timestamp
Returns the current UTC timestamp.
§Panics
With native backing, panics if the clock is already mutably borrowed.
Sourcepub fn set_time_alert(
&self,
name: &str,
alert_time: Timestamp,
callback: Option<TimeEventCallback>,
allow_past: Option<bool>,
) -> Result<()>
pub fn set_time_alert( &self, name: &str, alert_time: Timestamp, callback: Option<TimeEventCallback>, allow_past: Option<bool>, ) -> Result<()>
Sets a time alert for the specified UTC timestamp.
See Clock::set_time_alert for timing and callback selection semantics.
§Errors
Returns an error if the timestamp cannot be converted to [UnixNanos] or the backing clock
rejects the alert.
§Panics
With native backing, panics if the clock is already borrowed.
Sourcepub fn set_time_alert_ns(
&self,
name: &str,
alert_time_ns: UnixNanos,
callback: Option<TimeEventCallback>,
allow_past: Option<bool>,
) -> Result<()>
pub fn set_time_alert_ns( &self, name: &str, alert_time_ns: UnixNanos, callback: Option<TimeEventCallback>, allow_past: Option<bool>, ) -> Result<()>
Sets a time alert for the specified UNIX nanosecond timestamp.
See Clock::set_time_alert_ns for timing and callback selection semantics.
§Errors
Returns an error if the backing clock rejects the alert.
§Panics
With native backing, panics if the clock is already borrowed.
Sourcepub fn set_timer(
&self,
name: &str,
interval: Duration,
start_time: Option<Timestamp>,
stop_time: Option<Timestamp>,
callback: Option<TimeEventCallback>,
allow_past: Option<bool>,
fire_immediately: Option<bool>,
) -> Result<()>
pub fn set_timer( &self, name: &str, interval: Duration, start_time: Option<Timestamp>, stop_time: Option<Timestamp>, callback: Option<TimeEventCallback>, allow_past: Option<bool>, fire_immediately: Option<bool>, ) -> Result<()>
Sets an interval timer using UTC timestamps.
See Clock::set_timer for scheduling and callback selection semantics.
§Errors
Returns an error if the interval exceeds u64::MAX nanoseconds, a timestamp cannot be
converted to [UnixNanos], or the backing clock rejects the timer.
§Panics
With native backing, panics if the clock is already borrowed.
Sourcepub fn set_timer_ns(
&self,
name: &str,
interval_ns: u64,
start_time_ns: Option<UnixNanos>,
stop_time_ns: Option<UnixNanos>,
callback: Option<TimeEventCallback>,
allow_past: Option<bool>,
fire_immediately: Option<bool>,
) -> Result<()>
pub fn set_timer_ns( &self, name: &str, interval_ns: u64, start_time_ns: Option<UnixNanos>, stop_time_ns: Option<UnixNanos>, callback: Option<TimeEventCallback>, allow_past: Option<bool>, fire_immediately: Option<bool>, ) -> Result<()>
Sets an interval timer using UNIX nanosecond timestamps.
See Clock::set_timer_ns for scheduling and callback selection semantics.
§Errors
Returns an error if the backing clock rejects the timer.
§Panics
With native backing, panics if the clock is already borrowed.
Sourcepub fn timer_names(&self) -> Vec<String>
pub fn timer_names(&self) -> Vec<String>
Returns the names of active timers.
§Panics
With native backing, panics if the clock is already mutably borrowed.
Sourcepub fn timer_count(&self) -> usize
pub fn timer_count(&self) -> usize
Returns the count of active timers.
§Panics
With native backing, panics if the clock is already mutably borrowed.
Sourcepub fn timer_exists(&self, name: &str) -> bool
pub fn timer_exists(&self, name: &str) -> bool
Returns whether an active timer named name exists.
§Panics
With native backing, panics if the clock is already mutably borrowed.
Sourcepub fn next_time_ns(&self, name: &str) -> Option<UnixNanos>
pub fn next_time_ns(&self, name: &str) -> Option<UnixNanos>
Returns the next trigger timestamp for the active timer named name.
Returns None if no active timer with that name exists.
§Panics
With native backing, panics if the clock is already mutably borrowed.
Sourcepub fn cancel_timer(&self, name: &str)
pub fn cancel_timer(&self, name: &str)
Cancels the timer named name, if it exists.
§Panics
With native backing, panics if the clock is already borrowed.