pub(crate) struct AttachmentVtable {
type_id: fn() -> TypeId,
handler_type_id: fn() -> TypeId,
drop: unsafe fn(NonNull<AttachmentData<Erased>>),
display: unsafe fn(RawAttachmentRef<'_>, &mut Formatter<'_>) -> Result,
debug: unsafe fn(RawAttachmentRef<'_>, &mut Formatter<'_>) -> Result,
preferred_formatting_style: unsafe fn(RawAttachmentRef<'_>, FormattingFunction) -> AttachmentFormattingStyle,
}Expand description
Vtable for type-erased attachment operations.
Contains function pointers for performing operations on attachments without knowing their concrete type at compile time.
§Safety Invariant
The fields drop, display, debug, and preferred_formatting_style are
guaranteed to point to the functions defined below instantiated with the
attachment type A and handler type H that were used to create this
AttachmentVtable.
Fields§
§type_id: fn() -> TypeIdGets the TypeId of the attachment type that was used to create this
AttachmentVtable.
handler_type_id: fn() -> TypeIdGets the TypeId of the handler that was used to create this
AttachmentVtable.
drop: unsafe fn(NonNull<AttachmentData<Erased>>)Drops the Box<AttachmentData<A>> instance pointed to by this
pointer.
display: unsafe fn(RawAttachmentRef<'_>, &mut Formatter<'_>) -> ResultFormats the attachment using the display method on the handler.
debug: unsafe fn(RawAttachmentRef<'_>, &mut Formatter<'_>) -> ResultFormats the attachment using the debug method on the handler.
preferred_formatting_style: unsafe fn(RawAttachmentRef<'_>, FormattingFunction) -> AttachmentFormattingStyleGet the formatting style preferred by the attachment when formatted as part of a report.
Implementations§
Source§impl AttachmentVtable
impl AttachmentVtable
Sourcepub(super) const fn new<A: 'static, H: AttachmentHandler<A>>() -> &'static Self
pub(super) const fn new<A: 'static, H: AttachmentHandler<A>>() -> &'static Self
Creates a new AttachmentVtable for the attachment type A and the
handler type H.
Sourcepub(super) fn type_id(&self) -> TypeId
pub(super) fn type_id(&self) -> TypeId
Gets the TypeId of the attachment type that was used to create this
AttachmentVtable.
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
AttachmentVtable.
Sourcepub(super) unsafe fn drop(&self, ptr: NonNull<AttachmentData<Erased>>)
pub(super) unsafe fn drop(&self, ptr: NonNull<AttachmentData<Erased>>)
Drops the Box<AttachmentData<A>> instance pointed to by this pointer.
§Safety
The caller must ensure:
- The pointer comes from
Box<AttachmentData<A>>viaBox::into_raw - This
AttachmentVtablemust be a vtable for the attachment type stored in theAttachmentData. - This method drops the
Box<AttachmentData<A>>, 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 display(
&self,
ptr: RawAttachmentRef<'_>,
formatter: &mut Formatter<'_>,
) -> Result
pub(super) unsafe fn display( &self, ptr: RawAttachmentRef<'_>, formatter: &mut Formatter<'_>, ) -> Result
Formats the attachment using the H::display function
used when creating this AttachmentVtable.
§Safety
The caller must ensure:
- This
AttachmentVtablemust be a vtable for the attachment type stored in theRawAttachmentRef.
Sourcepub(super) unsafe fn debug(
&self,
ptr: RawAttachmentRef<'_>,
formatter: &mut Formatter<'_>,
) -> Result
pub(super) unsafe fn debug( &self, ptr: RawAttachmentRef<'_>, formatter: &mut Formatter<'_>, ) -> Result
Formats the attachment using the H::debug function
used when creating this AttachmentVtable.
§Safety
The caller must ensure:
- This
AttachmentVtablemust be a vtable for the attachment type stored in theRawAttachmentRef.
Sourcepub(super) unsafe fn preferred_formatting_style(
&self,
ptr: RawAttachmentRef<'_>,
report_formatting_function: FormattingFunction,
) -> AttachmentFormattingStyle
pub(super) unsafe fn preferred_formatting_style( &self, ptr: RawAttachmentRef<'_>, report_formatting_function: FormattingFunction, ) -> AttachmentFormattingStyle
Gets the preferred formatting style using the
H::preferred_formatting_style function used when creating this
AttachmentVtable.
§Safety
The caller must ensure:
- This
AttachmentVtablemust be a vtable for the attachment type stored in theRawAttachmentRef.