from_context

Function from_context 

Source
pub fn from_context<C, F, R>(f: F) -> R
where F: FnOnce(Option<&C>) -> R, C: 'static,
Expand description

Provides immutable access to the current context value

§Type Parameters

  • C - The type of the context value to access
  • F - The function type that will operate on the context
  • R - The return type from the function

§Arguments

  • f - A function that receives an Option<&C> and returns R

§Examples

use with_async_context::from_context;

struct MyContext {
    some_value: String
}
let value = from_context(|ctx: Option<&MyContext>| {
    ctx.unwrap().some_value.clone()
});