Function with

Source
pub fn with<T, TFn, TRet>(key: &'static LocalKey<Scope<T>>, fun: TFn) -> TRet
where TFn: FnOnce(Option<&T>) -> TRet, T: ?Sized,
Expand description

Gets the reference to value from the current scope. Given function will receive None if this is not called within a scope.

See thread_scoped_ref for an example.