Skip to main content

ClockApi

Struct ClockApi 

Source
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>

Source

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.

Source

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.

Source

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.

Source

pub fn timestamp(&self) -> f64

Returns the current UNIX timestamp in seconds.

§Panics

With native backing, panics if the clock is already mutably borrowed.

Source

pub fn utc_now(&self) -> Timestamp

Returns the current UTC timestamp.

§Panics

With native backing, panics if the clock is already mutably borrowed.

Source

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.

Source

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.

Source

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.

Source

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.

Source

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.

Source

pub fn timer_count(&self) -> usize

Returns the count of active timers.

§Panics

With native backing, panics if the clock is already mutably borrowed.

Source

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.

Source

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.

Source

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.

Source

pub fn cancel_timers(&self)

Cancels all timers.

§Panics

With native backing, panics if the clock is already borrowed.

Trait Implementations§

Source§

impl<'a> Debug for ClockApi<'a>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'a> !RefUnwindSafe for ClockApi<'a>

§

impl<'a> !Send for ClockApi<'a>

§

impl<'a> !Sync for ClockApi<'a>

§

impl<'a> !UnwindSafe for ClockApi<'a>

§

impl<'a> Freeze for ClockApi<'a>

§

impl<'a> Unpin for ClockApi<'a>

§

impl<'a> UnsafeUnpin for ClockApi<'a>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more