pub struct LocalRecorderGuard<'a> { /* private fields */ }
Expand description
Guard for setting a local recorder.
When using a local recorder, we take a reference to the recorder and only hold it for as long as the duration of the closure. However, we must store this reference in a static variable (thread-local storage) so that it can be accessed by the macros. This guard ensures that the pointer we store to the reference is cleared when the guard is dropped, so that it can’t be used after the closure has finished, even if the closure panics and unwinds the stack.
§Note
The guard has a lifetime parameter 'a
that is bounded using a PhantomData
type. This upholds the guard’s
contravariance, it must live at most as long as the recorder it takes a reference to. The bounded lifetime
prevents accidental use-after-free errors when using a guard directly through crate::set_default_local_recorder
.