AttachmentVtable

Struct AttachmentVtable 

Source
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() -> TypeId

Gets the TypeId of the attachment type that was used to create this AttachmentVtable.

§handler_type_id: fn() -> TypeId

Gets 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<'_>) -> Result

Formats the attachment using the display method on the handler.

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

Formats the attachment using the debug method on the handler.

§preferred_formatting_style: unsafe fn(RawAttachmentRef<'_>, FormattingFunction) -> AttachmentFormattingStyle

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

Implementations§

Source§

impl AttachmentVtable

Source

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.

Source

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

Gets the TypeId of the attachment type that was used to create this AttachmentVtable.

Source

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

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

Source

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:

  1. The pointer comes from Box<AttachmentData<A>> via Box::into_raw
  2. This AttachmentVtable must be a vtable for the attachment type stored in the AttachmentData.
  3. 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.
Source

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:

  1. This AttachmentVtable must be a vtable for the attachment type stored in the RawAttachmentRef.
Source

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:

  1. This AttachmentVtable must be a vtable for the attachment type stored in the RawAttachmentRef.
Source

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:

  1. This AttachmentVtable must be a vtable for the attachment type stored in the RawAttachmentRef.

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.