Skip to main content

ExecutorClock

Trait ExecutorClock 

pub trait ExecutorClock:
    Clone
    + Send
    + Sync
    + 'static {
    type Instant: Send + 'static;

    // Required methods
    fn now(&self) -> Result<Self::Instant>;
    fn checked_add(
        &self,
        now: &Self::Instant,
        duration: Duration,
    ) -> Result<Self::Instant>;
    fn remaining(
        &self,
        now: &Self::Instant,
        deadline: &Self::Instant,
    ) -> Result<Duration>;
}
Expand description

一份逻辑时间轴;克隆(Clone)不得改变起点或产生另一份独立时间。

正常取时不推进任何任务(Task)或队列。实际系统取时和竞争成本由实现说明; 不以旧缓存冒充新鲜时间,不用时钟值代替业务数据的同步。

Required Associated Types§

type Instant: Send + 'static

与接入的定时来源相同的时间点(time point);不要求Copy、Ord、Sync或Unpin。

Required Methods§

fn now(&self) -> Result<Self::Instant>

一次真实采样并采用同源单调结果;原失败报告(Report)原样返回。

fn checked_add( &self, now: &Self::Instant, duration: Duration, ) -> Result<Self::Instant>

对显式原时刻受检相加;不再次采样,不在越界时回绕或饱和成正常截止。

fn remaining( &self, now: &Self::Instant, deadline: &Self::Instant, ) -> Result<Duration>

计算到显式截止的剩余时长;已到或已过返回零,不再次取时。 输入必须来自同一时间轴;实现可报告不能验证或越界的输入。

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§