pub trait Clock {
Show 13 methods
// Required methods
fn timestamp_ns(&self) -> UnixNanos;
fn timestamp_us(&self) -> u64;
fn timestamp_ms(&self) -> u64;
fn timestamp(&self) -> f64;
fn timer_names(&self) -> Vec<&str>;
fn timer_count(&self) -> usize;
fn register_default_handler(&mut self, callback: TimeEventCallback);
fn set_time_alert_ns(
&mut self,
name: &str,
alert_time_ns: UnixNanos,
callback: Option<TimeEventCallback>,
);
fn set_timer_ns(
&mut self,
name: &str,
interval_ns: u64,
start_time_ns: UnixNanos,
stop_time_ns: Option<UnixNanos>,
callback: Option<TimeEventCallback>,
);
fn next_time_ns(&self, name: &str) -> UnixNanos;
fn cancel_timer(&mut self, name: &str);
fn cancel_timers(&mut self);
// Provided method
fn utc_now(&self) -> DateTime<Utc> { ... }
}
Expand description
Represents a type of clock.
§Notes
An active timer is one which has not expired (timer.is_expired == False
).
Required Methods§
sourcefn timestamp_ns(&self) -> UnixNanos
fn timestamp_ns(&self) -> UnixNanos
Returns the current UNIX timestamp in nanoseconds (ns).
sourcefn timestamp_us(&self) -> u64
fn timestamp_us(&self) -> u64
Returns the current UNIX timestamp in microseconds (μs).
sourcefn timestamp_ms(&self) -> u64
fn timestamp_ms(&self) -> u64
Returns the current UNIX timestamp in milliseconds (ms).
sourcefn timer_names(&self) -> Vec<&str>
fn timer_names(&self) -> Vec<&str>
Returns the names of active timers in the clock.
sourcefn timer_count(&self) -> usize
fn timer_count(&self) -> usize
Returns the count of active timers in the clock.
sourcefn register_default_handler(&mut self, callback: TimeEventCallback)
fn register_default_handler(&mut self, callback: TimeEventCallback)
Register a default event handler for the clock. If a Timer
does not have an event handler, then this handler is used.
sourcefn set_time_alert_ns(
&mut self,
name: &str,
alert_time_ns: UnixNanos,
callback: Option<TimeEventCallback>,
)
fn set_time_alert_ns( &mut self, name: &str, alert_time_ns: UnixNanos, callback: Option<TimeEventCallback>, )
Set a Timer
to alert at a particular time. Optional
callback gets used to handle generated events.
sourcefn set_timer_ns(
&mut self,
name: &str,
interval_ns: u64,
start_time_ns: UnixNanos,
stop_time_ns: Option<UnixNanos>,
callback: Option<TimeEventCallback>,
)
fn set_timer_ns( &mut self, name: &str, interval_ns: u64, start_time_ns: UnixNanos, stop_time_ns: Option<UnixNanos>, callback: Option<TimeEventCallback>, )
Set a Timer
to start alerting at every interval
between start and stop time. Optional callback gets
used to handle generated event.