Skip to main content

HeapElement

Trait HeapElement 

Source
pub unsafe trait HeapElement {
    // Required method
    unsafe fn release_elem(ptr: *const Self);
}
Expand description

v2-raw HeapHeader-equipped element carrier trait.

Implementors are #[repr(C)] structs with HeapHeader at offset 0. The trait dispatches per-T release at compile time via the Rust type system; TypedArray<*const T: HeapElement>::drop_array_heap calls T::release_elem(elem_ptr) for each stored element.

§Safety

Implementors must guarantee:

  1. Self is #[repr(C)] with a HeapHeader field at offset 0.
  2. release_elem(ptr) is sound when ptr points to a live Self allocation (one that the implementor’s allocator produced and that has not yet been freed).
  3. release_elem(ptr) decrements the refcount via v2_release and, if v2_release returns true, fully deallocates the allocation (including any nested payload buffers per the implementor’s drop semantics).

Required Methods§

Source

unsafe fn release_elem(ptr: *const Self)

Decrement the reference count of *ptr. If the refcount reaches zero, fully deallocate the object (including any nested payload buffers per the implementor’s drop semantics).

§Safety

ptr must point to a valid, live Self allocated via the implementor’s canonical v2-raw allocator. After this call returns, ptr must not be dereferenced (the allocation may have been freed).

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§