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, andpreferred_context_formatting_styleall point to the functions defined below - The concrete pointers are all instantiated with the same context type
Cand handler typeHthat were used to create thisReportVtable.
Fields§
§type_id: fn() -> TypeIdGets the TypeId of the context type that was used to create this
ReportVtable.
handler_type_id: fn() -> TypeIdGets 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>>) -> RawReportClones the triomphe::Arc<ReportData<C>> pointed to by this pointer.
strong_count: unsafe fn(RawReportRef<'_>) -> usizeGets 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<'_>) -> ResultFormats the report using the display method on the handler.
debug: unsafe fn(RawReportRef<'_>, &mut Formatter<'_>) -> ResultFormats the report using the debug method on the handler.
preferred_context_formatting_style: unsafe fn(RawReportRef<'_>, FormattingFunction) -> ContextFormattingStyleGet the formatting style preferred by the context when formatted as part of a report.
Implementations§
Source§impl ReportVtable
impl ReportVtable
Sourcepub(super) const fn new<C: 'static, H: ContextHandler<C>>() -> &'static Self
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.
Sourcepub(super) fn type_id(&self) -> TypeId
pub(super) fn type_id(&self) -> TypeId
Gets the TypeId of the context type that was used to create this
ReportVtable.
Sourcepub(super) fn handler_type_id(&self) -> TypeId
pub(super) fn handler_type_id(&self) -> TypeId
Gets the TypeId of the handler that was used to create this
ReportVtable.
Sourcepub(super) unsafe fn drop(&self, ptr: NonNull<ReportData<Erased>>)
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:
- The pointer comes from a
triomphe::Arc<ReportData<C>>turned into a pointer viatriomphe::Arc::into_raw - This
ReportVtablemust be a vtable for the context type stored in theReportData. - 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.
Sourcepub(super) unsafe fn clone_arc(
&self,
ptr: NonNull<ReportData<Erased>>,
) -> RawReport
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:
- The pointer comes from a
triomphe::Arc<ReportData<C>>turned into a pointer viatriomphe::Arc::into_raw - This
ReportVtablemust be a vtable for the context type stored in theReportData. - All other references to this report are compatible with shared
ownership. Specifically none of them assume that the strong_count is
1.
Sourcepub(super) unsafe fn strong_count<'a>(&self, ptr: RawReportRef<'a>) -> usize
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:
- This
ReportVtablemust be a vtable for the context type stored in theRawReportRef.
Sourcepub(super) unsafe fn source<'a>(
&self,
ptr: RawReportRef<'a>,
) -> Option<&'a (dyn Error + 'static)>
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:
- This
ReportVtablemust be a vtable for the context type stored in theRawReportRef.
Sourcepub(super) unsafe fn display(
&self,
ptr: RawReportRef<'_>,
formatter: &mut Formatter<'_>,
) -> Result
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:
- This
ReportVtablemust be a vtable for the context type stored in theRawReportRef.
Sourcepub(super) unsafe fn debug(
&self,
ptr: RawReportRef<'_>,
formatter: &mut Formatter<'_>,
) -> Result
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:
- This
ReportVtablemust be a vtable for the context type stored in theRawReportRef.
Sourcepub(super) unsafe fn preferred_context_formatting_style(
&self,
ptr: RawReportRef<'_>,
report_formatting_function: FormattingFunction,
) -> ContextFormattingStyle
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:
- This
ReportVtablemust be a vtable for the context type stored in theRawReportRef.