跳到主要内容

Runtime

搜索

trait Runtime 

源代码
pub trait Runtime:
    Send
    + Sync
    + Debug
    + 'static {
    // Required methods
    fn new_timer(&self, i: Instant) -> Pin<Box<dyn AsyncTimer>>;
    fn spawn(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>);
    fn wrap_udp_socket(&self, t: UdpSocket) -> Result<Arc<dyn AsyncUdpSocket>>;

    // Provided method
    fn now(&self) -> Instant { ... }
}
展开描述

对 I/O 与定时器操作的抽象,用于运行时无关性

必需方法§

源代码

fn new_timer(&self, i: Instant) -> Pin<Box<dyn AsyncTimer>>

构造一个将在 i 时刻触发的定时器

源代码

fn spawn(&self, future: Pin<Box<dyn Future<Output = ()> + Send>>)

在后台将 future 驱动至完成

源代码

fn wrap_udp_socket(&self, t: UdpSocket) -> Result<Arc<dyn AsyncUdpSocket>>

t 转换为本运行时所使用的套接字类型

提供方法§

源代码

fn now(&self) -> Instant

查询当前时间

允许在测试中模拟时间的流逝。

实现者§