pub trait ContextResource<'ctx, Ctx> {
type Spore: ContextSpore<Ctx, Resource<'ctx> = Self>
where Ctx: 'ctx;
// Required method
fn sporulate(self) -> Self::Spore;
}
Expand description
上下文资源。
这个 trait 将资源的生命周期与上下文绑定,以保证资源的申请和释放在同一个上下文中完成。
处于上下文资源状态的资源对象可以参与相应的功能。例如,处于上下文资源状态的存储区域可以读写。
但是业务逻辑中,不可避免地会出现需要暂时切换当前上下文而不释放资源的情况,
因此资源提供 sporulate
方法将资源转换为孢子。
Required Associated Types§
Sourcetype Spore: ContextSpore<Ctx, Resource<'ctx> = Self>
where
Ctx: 'ctx
type Spore: ContextSpore<Ctx, Resource<'ctx> = Self> where Ctx: 'ctx
上下文资源对应的孢子类型。
这个约束保证了资源与孢子一一对应。