Module raw

Module raw 

Source
Expand description

Type-erased attachment pointer types.

This module encapsulates the ptr field of RawAttachment and RawAttachmentRef, ensuring it is only visible within this module. This visibility restriction guarantees the safety invariant: the pointer always comes from Box<AttachmentData<A>>.

§Safety Invariant

Since the ptr field can only be set via RawAttachment::new (which creates it from Box::into_raw), and cannot be modified afterward (no pub or pub(crate) fields), the pointer provenance remains valid throughout the value’s lifetime.

The RawAttachment::drop implementation relies on this invariant to safely reconstruct the Box and deallocate the memory.

§Type Erasure

The concrete type parameter A is erased by casting to AttachmentData<Erased>. The vtable stored within the AttachmentData provides the runtime type information needed to safely downcast and format attachments.

Structs§

RawAttachment
A pointer to an AttachmentData that is guaranteed to point to an initialized instance of an AttachmentData<A> for some specific A, though we do not know which actual A it is.
RawAttachmentRef
A lifetime-bound pointer to an AttachmentData that is guaranteed to point to an initialized instance of an AttachmentData<A> for some specific A, though we do not know which actual A it is.