pub struct RecoverableRecorder<R> { /* private fields */ }
Expand description
Wraps a recorder to allow for recovering it after being installed.
Installing a recorder generally involves providing an owned value, which means that it is not possible to recover the recorder after it has been installed. For some recorder implementations, it can be important to perform finalization before the application exits, which is not possible if the application cannot consume the recorder.
RecoverableRecorder
allows wrapping a recorder such that a weak reference to it is installed
globally, while the recorder itself is held by RecoveryHandle<R>
. This allows the recorder to
be used globally so long as the recovery handle is active, keeping the original recorder alive.
§As a drop guard
While RecoveryHandle<R>
provides a method to manually recover the recorder directly, one
particular benefit is that due to how the recorder is wrapped, when RecoveryHandle<R>
is
dropped, and the last active reference to the wrapped recorder is dropped, the recorder itself
will be dropped.
This allows using RecoveryHandle<R>
as a drop guard, ensuring that by dropping it, the
recorder itself will be dropped, and any finalization logic implemented for the recorder will be
run.
Implementations§
source§impl<R: Recorder + Sync + Send + 'static> RecoverableRecorder<R>
impl<R: Recorder + Sync + Send + 'static> RecoverableRecorder<R>
sourcepub fn install(self) -> Result<RecoveryHandle<R>, SetRecorderError<R>>
pub fn install(self) -> Result<RecoveryHandle<R>, SetRecorderError<R>>
Installs the wrapped recorder globally, returning a handle to recover it.
A weakly-referenced version of the recorder is installed globally, while the original
recorder is held within RecoverableRecorder
, and can be recovered by calling into_inner
.
§Errors
If a recorder is already installed, an error is returned containing the original recorder.