pub trait Clock {
Show 14 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 get_handler(&self, event: TimeEvent) -> TimeEventHandlerV2;
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 get_handler(&self, event: TimeEvent) -> TimeEventHandlerV2
fn get_handler(&self, event: TimeEvent) -> TimeEventHandlerV2
Get handler for TimeEvent
Note: Panics if the event does not have an associated handler
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.
Sourcefn next_time_ns(&self, name: &str) -> UnixNanos
fn next_time_ns(&self, name: &str) -> UnixNanos
Returns the time interval in which the timer name
is triggered.
If the timer doesn’t exist 0 is returned.