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 RecoverableRecorder. This allows for recovering the recorder whenever the application chooses.

As a drop guard

While RecoverableRecorder provides a method to manually recover the recorder directly, one particular benefit is that due to how the recorder is wrapped, when RecoverableRecorder is dropped, and the last active reference to it is dropped, the recorder itself will be dropped.

This allows using RecoverableRecorder 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 from_recorder(recorder: R) -> Result<Self, SetRecorderError>

Creates a new RecoverableRecorder, wrapping the given recorder.

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.

source

pub fn into_inner(self) -> R

Consumes this wrapper, returning the original recorder.

This method will loop until there are no active weak references to the recorder. It is not advised to call this method under heavy load, as doing so is not deterministic or ordered and may block for an indefinite amount of time.

Auto Trait Implementations§

§

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

§

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

§

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

§

impl<R> Unpin for RecoverableRecorder<R>

§

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

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere 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 Twhere 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 = mem::align_of::<T>()

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 Twhere 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 Twhere 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.