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§
type Handle: Runtime<Notifier = Self::Notifier, Timer = Self::Timer, Handle = Self::Handle> + Clone + Send + Sync + 'static
Required Methods§
Provided Methods§
Sourcefn try_current() -> Result<Self::Handle, CurrentRuntimeAccessError>
fn try_current() -> Result<Self::Handle, CurrentRuntimeAccessError>
取得并克隆(Clone)当前所选原服务的共享句柄(shared handle),不产生本地或推进权限。 无当前目标、句柄类型(type)不匹配或线程局部存储(TLS)不可访问时返回对应错误。 有效公共选择在原服务关闭后仍可读取关闭事实,不会重新开放服务。
Sourcefn try_with_current<R>(
action: impl FnOnce(&Self::Handle) -> R,
) -> Result<R, CurrentRuntimeAccessError>
fn try_with_current<R>( action: impl FnOnce(&Self::Handle) -> R, ) -> Result<R, CurrentRuntimeAccessError>
同步借用不能逃逸或跨await;公共环境关闭后仍可读原关闭事实。
Sourcefn enter<R>(
&self,
action: impl FnOnce() -> R,
) -> Result<R, CurrentRuntimeAccessError>
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".