pub trait RawContext {
type Item;
private!();
}
pub trait Context {
type Ctx: RawContext;
fn ctx(&self) -> Self::Ctx;
fn ctx_mut(&mut self) -> &mut Self::Ctx;
fn replace_ctx(&mut self, ctx: Self::Ctx) -> Self::Ctx;
fn set_ctx(&mut self, ctx: Self::Ctx) -> &mut Self;
}
pub trait Contextual {
type Ctx: RawContext;
fn ctx(&self) -> Self::Ctx;
fn ctx_mut(&mut self) -> &mut Self::Ctx;
fn replace_ctx(&mut self, ctx: Self::Ctx) -> Self::Ctx {
core::mem::replace(self.ctx_mut(), ctx)
}
fn set_ctx(&mut self, ctx: Self::Ctx) -> &mut Self {
*self.ctx_mut() = ctx;
self
}
fn swap_ctx(&mut self, other: &mut Self) {
core::mem::swap(self.ctx_mut(), other.ctx_mut());
}
fn take_ctx(&mut self) -> Self::Ctx
where
Self::Ctx: Default,
{
core::mem::take(self.ctx_mut())
}
}