Skip to main content

RuntimeOps

Trait RuntimeOps 

Source
pub trait RuntimeOps: Send + Sync {
    // Required methods
    fn name(&self) -> &'static str;
    fn now_nanos(&self) -> u64;
    fn unix_time(&self) -> Option<(u64, u32)>;
    fn sleep(&self, d: Duration) -> BoxFuture;
    fn log(&self, level: LogLevel, msg: &str);
}
Expand description

Object-safe runtime capabilities: identity, time, sleep, and logging.

Implemented by every runtime adapter (TokioAdapter, EmbassyAdapter, WasmAdapter) so a runtime can travel as Arc<dyn RuntimeOps> instead of a generic parameter.

Required Methods§

Source

fn name(&self) -> &'static str

Short adapter identity, e.g. "tokio".

Source

fn now_nanos(&self) -> u64

Monotonic clock reading in nanoseconds from an arbitrary epoch.

Only differences between two readings are meaningful. Never decreases; saturates at u64::MAX rather than wrapping.

Source

fn unix_time(&self) -> Option<(u64, u32)>

Wall-clock time as (seconds, nanoseconds) since the Unix epoch, if the runtime has a real-time clock.

Returns None on platforms without a wall clock (e.g. a bare MCU with no RTC anchor), where only monotonic time is available.

Source

fn sleep(&self, d: Duration) -> BoxFuture

Completes after at least d has elapsed.

Source

fn log(&self, level: LogLevel, msg: &str)

Emits msg at level through the adapter’s logging backend.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§