Skip to main content

Context

Trait Context 

Source
pub trait Context: Send + Sync {
    // Required methods
    fn insert<T: Any + Send + Sync>(&self, value: T);
    fn get<T: Any + Send + Sync>(&self) -> Option<Arc<T>>;
    fn remove<T: Any + Send + Sync>(&self) -> Option<Arc<T>>;
}
Expand description

Shared interface for type-safe, heterogeneous key-value storage.

Both AppContext and RequestContext implement this trait, allowing generic helper functions to work with either context type.

Required Methods§

Source

fn insert<T: Any + Send + Sync>(&self, value: T)

Insert a value of any type into the context.

Source

fn get<T: Any + Send + Sync>(&self) -> Option<Arc<T>>

Retrieve a value by its type from the context.

Source

fn remove<T: Any + Send + Sync>(&self) -> Option<Arc<T>>

Remove and return a value by its type from the context.

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§