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
Panics if native backing is used and 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
Panics if native backing is used and 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
Panics if native backing is used and the clock is already mutably borrowed.
Sourcepub fn timestamp(&self) -> f64
pub fn timestamp(&self) -> f64
Returns the current UNIX timestamp in seconds.
§Panics
Panics if native backing is used and the clock is already mutably borrowed.
Sourcepub fn utc_now(&self) -> Timestamp
pub fn utc_now(&self) -> Timestamp
Returns the current UTC timestamp.
§Panics
Panics if native backing is used and 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. - The native 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.
- The native 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::MAXnanoseconds, a timestamp cannot be converted to [UnixNanos], or the backing clock rejects the timer. - The native clock is already borrowed.
Sourcepub fn set_timer_ns(
&self,
name: &str,
interval_ns: DurationNanos,
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: DurationNanos, 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.
- The native clock is already borrowed.
Sourcepub fn set_timer_schedule(
&self,
name: &str,
schedule: Arc<dyn TimerSchedule>,
stop_time_ns: Option<UnixNanos>,
callback: Option<TimeEventCallback>,
allow_past: Option<bool>,
fire_immediately: Option<bool>,
) -> Result<()>
pub fn set_timer_schedule( &self, name: &str, schedule: Arc<dyn TimerSchedule>, stop_time_ns: Option<UnixNanos>, callback: Option<TimeEventCallback>, allow_past: Option<bool>, fire_immediately: Option<bool>, ) -> Result<()>
Registers a source of absolute UTC deadlines.
See Clock::set_timer_schedule for timer lifecycle, flag, and callback semantics.
§Errors
Returns an error if:
- The backing clock rejects the schedule, or operation handlers back this API.
- The native clock is already borrowed.
Sourcepub fn set_timer_zoned(
&self,
name: &str,
interval: Span,
start_time: &Zoned,
stop_time: Option<Timestamp>,
callback: Option<TimeEventCallback>,
allow_past: Option<bool>,
fire_immediately: Option<bool>,
) -> Result<()>
pub fn set_timer_zoned( &self, name: &str, interval: Span, start_time: &Zoned, stop_time: Option<Timestamp>, callback: Option<TimeEventCallback>, allow_past: Option<bool>, fire_immediately: Option<bool>, ) -> Result<()>
Sets a calendar timer stepped in the timezone of start_time.
Each occurrence is calculated from the original start. Days, weeks, months, and years
preserve local wall-clock time across DST changes; time-only spans use elapsed time.
Event timestamps remain UTC. See Clock::set_timer_ns for flags and callback selection.
§Errors
Returns an error if:
- The interval is not positive, or start or stop timestamps are outside
the [
UnixNanos] range. - The backing clock rejects the schedule, or operation handlers back this API.
- The native 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
Panics if native backing is used and 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
Panics if native backing is used and 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
Panics if native backing is used and 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
Panics if native backing is used and 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
Panics if native backing is used and the clock is already borrowed.