Trait Contextual

Source
pub trait Contextual {
    type Ctx: RawContext;

    // Required methods
    fn ctx(&self) -> Self::Ctx;
    fn ctx_mut(&mut self) -> &mut Self::Ctx;

    // Provided methods
    fn replace_ctx(&mut self, ctx: Self::Ctx) -> Self::Ctx { ... }
    fn set_ctx(&mut self, ctx: Self::Ctx) -> &mut Self { ... }
    fn swap_ctx(&mut self, other: &mut Self) { ... }
    fn take_ctx(&mut self) -> Self::Ctx
       where Self::Ctx: Default { ... }
}
Expand description

Contextual is a trait for denoting types that are associated with a particular context.

Required Associated Types§

Required Methods§

Source

fn ctx(&self) -> Self::Ctx

returns an immutable reference to the current context.

Source

fn ctx_mut(&mut self) -> &mut Self::Ctx

returns a mutable reference to the current context

Provided Methods§

Source

fn replace_ctx(&mut self, ctx: Self::Ctx) -> Self::Ctx

replace with another and return the previous context

Source

fn set_ctx(&mut self, ctx: Self::Ctx) -> &mut Self

update the current context and return a mutable reference to the instance

Source

fn swap_ctx(&mut self, other: &mut Self)

swap out the context’s of two instances.

Source

fn take_ctx(&mut self) -> Self::Ctx
where Self::Ctx: Default,

take the current context and return it, leaving the default context in its place.

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§