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_ref
和 sprout_mut
方法获取资源的不可变和可变引用。
这些方法将引入运行时检查以保证孢子在正确的上下文上复原。
Required Associated Types§
Sourcetype Resource<'ctx>: ContextResource<'ctx, Ctx, Spore = Self>
where
Ctx: 'ctx
type Resource<'ctx>: ContextResource<'ctx, Ctx, Spore = Self> where Ctx: 'ctx
上下文孢子对应的资源类型。
这个约束保证了资源与孢子一一对应。
Required Methods§
Sourcefn sprout_ref<'ctx>(&'ctx self, ctx: &'ctx Ctx) -> &'ctx Self::Resource<'ctx>
fn sprout_ref<'ctx>(&'ctx self, ctx: &'ctx Ctx) -> &'ctx Self::Resource<'ctx>
Sourcefn sprout_mut<'ctx>(
&'ctx mut self,
ctx: &'ctx Ctx,
) -> &'ctx mut Self::Resource<'ctx>
fn sprout_mut<'ctx>( &'ctx mut self, ctx: &'ctx Ctx, ) -> &'ctx mut Self::Resource<'ctx>
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.