Function from_context_mut

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

Provides mutable 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<&mut C> and returns R

§Examples

use with_async_context::from_context_mut;

struct MyContext {
    counter: i32
}
from_context_mut(|ctx: Option<&mut MyContext>| {
    if let Some(ctx) = ctx {
        ctx.counter += 1;
    }
});