ContextSpore

Trait ContextSpore 

Source
pub trait ContextSpore<Ctx>:
    'static
    + Send
    + Sync {
    type Resource<'ctx>: ContextResource<'ctx, Ctx, Spore = Self>
       where Ctx: 'ctx;

    // Required methods
    fn sprout(self, ctx: &Ctx) -> Self::Resource<'_>;
    fn sprout_ref<'ctx>(
        &'ctx self,
        ctx: &'ctx Ctx,
    ) -> &'ctx Self::Resource<'ctx>;
    fn sprout_mut<'ctx>(
        &'ctx mut self,
        ctx: &'ctx Ctx,
    ) -> &'ctx mut Self::Resource<'ctx>;
}
Expand description

上下文孢子。

这个 trait 移除上下文资源的生命周期约束,从而允许在上下文被换出时暂时保持资源存在。 但处于上下文孢子状态的资源通常不再允许参与相应的功能。 只有当申请这些资源的上下文被换回,并在上下文上将孢子恢复为资源后才能继续发挥作用。 上下文孢子提供 sprout 方法将孢子转换为资源, 以及 sprout_refsprout_mut 方法获取资源的不可变和可变引用。 这些方法将引入运行时检查以保证孢子在正确的上下文上复原。

Required Associated Types§

Source

type Resource<'ctx>: ContextResource<'ctx, Ctx, Spore = Self> where Ctx: 'ctx

上下文孢子对应的资源类型。

这个约束保证了资源与孢子一一对应。

Required Methods§

Source

fn sprout(self, ctx: &Ctx) -> Self::Resource<'_>

将孢子转换为资源。

§Safety

这个转换的安全性来源于运行时检查孢子是否属于已加载的目标上下文。

Source

fn sprout_ref<'ctx>(&'ctx self, ctx: &'ctx Ctx) -> &'ctx Self::Resource<'ctx>

从孢子中借出资源的不可变引用。

§Safety

这个转换的安全性来源于运行时检查孢子是否属于已加载的目标上下文。

Source

fn sprout_mut<'ctx>( &'ctx mut self, ctx: &'ctx Ctx, ) -> &'ctx mut Self::Resource<'ctx>

从孢子中借出资源的可变引用。

§Safety

这个转换的安全性来源于运行时检查孢子是否属于已加载的目标上下文。

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§