Function frame_support::dispatch_context::with_context
source · pub fn with_context<T: 'static, R>(
callback: impl FnOnce(&mut Value<'_, T>) -> R,
) -> Option<R>
Expand description
Runs the given callback
in the dispatch context and gives access to some user defined value.
Passes the a mutable reference of Value
to the callback. The value will be of type T
and
is identified using the TypeId
of T
. This means that T
should be some unique type to
make the value unique. If no value is set yet Value::get()
and Value::get_mut()
will
return None
. It is totally valid to have some T
that is shared between different callers to
have access to the same value.
Returns None
if the current context is not a dispatch context. To create a context it is
required to call run_in_context
with the closure to execute in this context. So, for example
in tests it could be that there isn’t any dispatch context or when calling a dispatchable like a
normal Rust function from some FRAME hook.