Skip to main content

UninitRecyclable

Trait UninitRecyclable 

Source
pub unsafe trait UninitRecyclable: Recyclable {
    // Required methods
    fn allocate_uninit() -> Result<NonNull<MaybeUninit<Self>>, AllocError>;
    unsafe fn recycle_uninit(ptr: NonNull<MaybeUninit<Self>>);
}
Expand description

Trait for types that can be allocated in an uninitialized state.

§Safety

Implementing this trait is unsafe because the implementer must ensure that:

  • allocate_uninit returns a valid pointer to uninitialized memory that can be safely deallocated by recycle_uninit.
  • recycle_uninit correctly deallocates the pointer without dropping the content (as it is uninitialized) and does not cause double-free or use-after-free.

Required Methods§

Source

fn allocate_uninit() -> Result<NonNull<MaybeUninit<Self>>, AllocError>

Allocates a new uninitialized instance of Self.

Source

unsafe fn recycle_uninit(ptr: NonNull<MaybeUninit<Self>>)

Recycles an uninitialized object.

§Safety
  • The caller must ensure that ptr points to a valid (but possibly uninitialized) instance of Self that has no other references.
  • The caller must not use the pointer or any references derived from it after this call.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§