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_uninitreturns a valid pointer to uninitialized memory that can be safely deallocated byrecycle_uninit.recycle_uninitcorrectly deallocates the pointer without dropping the content (as it is uninitialized) and does not cause double-free or use-after-free.
Required Methods§
Sourcefn allocate_uninit() -> Result<NonNull<MaybeUninit<Self>>, AllocError>
fn allocate_uninit() -> Result<NonNull<MaybeUninit<Self>>, AllocError>
Allocates a new uninitialized instance of Self.
Sourceunsafe fn recycle_uninit(ptr: NonNull<MaybeUninit<Self>>)
unsafe fn recycle_uninit(ptr: NonNull<MaybeUninit<Self>>)
Recycles an uninitialized object.
§Safety
- The caller must ensure that
ptrpoints to a valid (but possibly uninitialized) instance ofSelfthat 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.