ReportVtable

Struct ReportVtable 

Source
pub(crate) struct ReportVtable {
    type_id: fn() -> TypeId,
    handler_type_id: fn() -> TypeId,
    drop: unsafe fn(NonNull<ReportData<Erased>>),
    clone_arc: unsafe fn(NonNull<ReportData<Erased>>) -> RawReport,
    strong_count: unsafe fn(RawReportRef<'_>) -> usize,
    source: unsafe fn(RawReportRef<'_>) -> Option<&(dyn Error + 'static)>,
    display: unsafe fn(RawReportRef<'_>, &mut Formatter<'_>) -> Result,
    debug: unsafe fn(RawReportRef<'_>, &mut Formatter<'_>) -> Result,
    preferred_context_formatting_style: unsafe fn(RawReportRef<'_>, FormattingFunction) -> ContextFormattingStyle,
}
Expand description

Vtable for type-erased report operations.

Contains function pointers for performing operations on reports without knowing their concrete type at compile time.

§Safety

The following safety invariants are guaranteed to be upheld as long as this struct exists:

  • The fields drop, clone_arc, strong_count, source, display, debug, and preferred_context_formatting_style all point to the functions defined below
  • The concrete pointers are all instantiated with the same context type C and handler type H that were used to create this ReportVtable.

Fields§

§type_id: fn() -> TypeId

Gets the TypeId of the context type that was used to create this ReportVtable.

§handler_type_id: fn() -> TypeId

Gets the TypeId of the handler that was used to create this ReportVtable.

§drop: unsafe fn(NonNull<ReportData<Erased>>)

Method to drop the triomphe::Arc<ReportData<C>> instance pointed to by this pointer.

§clone_arc: unsafe fn(NonNull<ReportData<Erased>>) -> RawReport

Clones the triomphe::Arc<ReportData<C>> pointed to by this pointer.

§strong_count: unsafe fn(RawReportRef<'_>) -> usize

Gets the strong count of the triomphe::Arc<ReportData<C>> pointed to by this pointer.

§source: unsafe fn(RawReportRef<'_>) -> Option<&(dyn Error + 'static)>

Returns a reference to the source of the error using the source method on the handler.

§display: unsafe fn(RawReportRef<'_>, &mut Formatter<'_>) -> Result

Formats the report using the display method on the handler.

§debug: unsafe fn(RawReportRef<'_>, &mut Formatter<'_>) -> Result

Formats the report using the debug method on the handler.

§preferred_context_formatting_style: unsafe fn(RawReportRef<'_>, FormattingFunction) -> ContextFormattingStyle

Get the formatting style preferred by the context when formatted as part of a report.

Implementations§

Source§

impl ReportVtable

Source

pub(super) const fn new<C: 'static, H: ContextHandler<C>>() -> &'static Self

Creates a new ReportVtable for the context type C and the handler type H.

Source

pub(super) fn type_id(&self) -> TypeId

Gets the TypeId of the context type that was used to create this ReportVtable.

Source

pub(super) fn handler_type_id(&self) -> TypeId

Gets the TypeId of the handler that was used to create this ReportVtable.

Source

pub(super) unsafe fn drop(&self, ptr: NonNull<ReportData<Erased>>)

Drops the triomphe::Arc<ReportData<C>> instance pointed to by this pointer.

§Safety

The caller must ensure:

  1. The pointer comes from a triomphe::Arc<ReportData<C>> turned into a pointer via triomphe::Arc::into_raw
  2. This ReportVtable must be a vtable for the context type stored in the ReportData.
  3. This method drops the triomphe::Arc<ReportData<C>>, so the caller must ensure that the pointer has not previously been dropped, that it is able to transfer ownership of the pointer, and that it will not use the pointer after calling this method.
Source

pub(super) unsafe fn clone_arc( &self, ptr: NonNull<ReportData<Erased>>, ) -> RawReport

Clones the triomphe::Arc<ReportData<C>> pointed to by this pointer.

§Safety

The caller must ensure:

  1. The pointer comes from a triomphe::Arc<ReportData<C>> turned into a pointer via triomphe::Arc::into_raw
  2. This ReportVtable must be a vtable for the context type stored in the ReportData.
  3. All other references to this report are compatible with shared ownership. Specifically none of them assume that the strong_count is 1.
Source

pub(super) unsafe fn strong_count<'a>(&self, ptr: RawReportRef<'a>) -> usize

Gets the strong count of the triomphe::Arc<ReportData<C>> pointed to by this pointer.

§Safety

The caller must ensure:

  1. This ReportVtable must be a vtable for the context type stored in the RawReportRef.
Source

pub(super) unsafe fn source<'a>( &self, ptr: RawReportRef<'a>, ) -> Option<&'a (dyn Error + 'static)>

Returns a reference to the source of the error using the H::source function used when creating this ReportVtable.

§Safety

The caller must ensure:

  1. This ReportVtable must be a vtable for the context type stored in the RawReportRef.
Source

pub(super) unsafe fn display( &self, ptr: RawReportRef<'_>, formatter: &mut Formatter<'_>, ) -> Result

Formats the report using the H::display function used when creating this ReportVtable.

§Safety

The caller must ensure:

  1. This ReportVtable must be a vtable for the context type stored in the RawReportRef.
Source

pub(super) unsafe fn debug( &self, ptr: RawReportRef<'_>, formatter: &mut Formatter<'_>, ) -> Result

Formats the given RawReportRef using the H::debug function used when creating this ReportVtable.

§Safety

The caller must ensure:

  1. This ReportVtable must be a vtable for the context type stored in the RawReportRef.
Source

pub(super) unsafe fn preferred_context_formatting_style( &self, ptr: RawReportRef<'_>, report_formatting_function: FormattingFunction, ) -> ContextFormattingStyle

Calls the H::preferred_formatting_style function to get the formatting style preferred by the context when formatted as part of a report.

§Safety

The caller must ensure:

  1. This ReportVtable must be a vtable for the context type stored in the RawReportRef.

Auto Trait Implementations§

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, U> TryFrom<U> for T
where U: Into<T>,

Source§

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>,

Source§

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.