Skip to main content

RuntimeContext

Trait RuntimeContext 

pub trait RuntimeContext: TaskDispatch + RuntimeTime {
    type Handle: Runtime<Notifier = Self::Notifier, Timer = Self::Timer, Handle = Self::Handle> + Clone + Send + Sync + 'static;

    // Required method
    fn handle(&self) -> Self::Handle;

    // Provided methods
    fn try_current() -> Result<Self::Handle, CurrentRuntimeAccessError> { ... }
    fn try_with_current<R>(
        action: impl FnOnce(&Self::Handle) -> R,
    ) -> Result<R, CurrentRuntimeAccessError> { ... }
    fn enter<R>(
        &self,
        action: impl FnOnce() -> R,
    ) -> Result<R, CurrentRuntimeAccessError> { ... }
}
Expand description

公共访问的目标与本地推进权限不同;显式enter只选择原服务。

Required Associated Types§

Source

type Handle: Runtime<Notifier = Self::Notifier, Timer = Self::Timer, Handle = Self::Handle> + Clone + Send + Sync + 'static

Required Methods§

Source

fn handle(&self) -> Self::Handle

取得原服务的共享句柄(shared handle);Clone不复制服务,普通释放不自动关闭。

Provided Methods§

Source

fn try_current() -> Result<Self::Handle, CurrentRuntimeAccessError>

取得并克隆(Clone)当前所选原服务的共享句柄(shared handle),不产生本地或推进权限。 无当前目标、句柄类型(type)不匹配或线程局部存储(TLS)不可访问时返回对应错误。 有效公共选择在原服务关闭后仍可读取关闭事实,不会重新开放服务。

Source

fn try_with_current<R>( action: impl FnOnce(&Self::Handle) -> R, ) -> Result<R, CurrentRuntimeAccessError>

同步借用不能逃逸或跨await;公共环境关闭后仍可读原关闭事实。

Source

fn enter<R>( &self, action: impl FnOnce() -> R, ) -> Result<R, CurrentRuntimeAccessError>

同目标允许嵌套,不授予本地权限;闭包返回Future不会延长本次选择范围。

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

§

impl<C, E, I, T> RuntimeContext for RuntimeHandle<C, E, I, T>

§

type Handle = RuntimeHandle<C, E, I, T>

§

impl<M, C, P, H, E, I, T> RuntimeContext for ConfiguredRuntime<M, C, P, H, E, I, T>