netstack3_base

Trait ContextProvider

Source
pub trait ContextProvider {
    type Context: Sized;

    // Required method
    fn context(&mut self) -> &mut Self::Context;
}
Expand description

A type that provides a context implementation.

This trait allows for CtxPair to hold context implementations agnostically of the storage method and how they’re implemented. For example, tests usually create API structs with a mutable borrow to contexts, while the core context exposed to bindings is implemented on an owned [CoreCtx] type.

The shape of this trait is equivalent to core::ops::DerefMut but we decide against using that because of the automatic dereferencing semantics the compiler provides around implementers of DerefMut.

Required Associated Types§

Source

type Context: Sized

The context provided by this ContextProvider.

Required Methods§

Source

fn context(&mut self) -> &mut Self::Context

Gets a mutable borrow to this context.

Implementations on Foreign Types§

Source§

impl<'a, T: Sized> ContextProvider for &'a mut T

Source§

type Context = T

Source§

fn context(&mut self) -> &mut Self::Context

Implementors§