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 + 'static> RecoverableRecorder<R>

source

pub fn new(recorder: R) -> Self

Creates a new RecoverableRecorder from the given recorder.

source

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.

Auto Trait Implementations§

§

impl<R> Freeze for RecoverableRecorder<R>

§

impl<R> RefUnwindSafe for RecoverableRecorder<R>
where R: RefUnwindSafe,

§

impl<R> Send for RecoverableRecorder<R>
where R: Sync + Send,

§

impl<R> Sync for RecoverableRecorder<R>
where R: Sync + Send,

§

impl<R> Unpin for RecoverableRecorder<R>

§

impl<R> UnwindSafe for RecoverableRecorder<R>
where R: RefUnwindSafe,

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

type Init = T

The type for initializers.
source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.