pub unsafe trait Recyclable: Sized {
// Required methods
fn allocate(value: Self) -> Result<NonNull<Self>, AllocError>;
unsafe fn recycle(ptr: NonNull<Self>);
// Provided method
unsafe fn recycle_ffi(ptr: *mut c_void) { ... }
}Expand description
Trait for types that can be recycled (deallocated).
§Safety
Implementing this trait is unsafe because the implementer must ensure that:
allocatereturns a valid pointer that can be safely deallocated byrecycle.recyclecorrectly deallocates the pointer and does not cause double-free or use-after-free.
Required Methods§
Sourcefn allocate(value: Self) -> Result<NonNull<Self>, AllocError>
fn allocate(value: Self) -> Result<NonNull<Self>, AllocError>
Allocates a new instance of Self.
Provided Methods§
Sourceunsafe fn recycle_ffi(ptr: *mut c_void)
unsafe fn recycle_ffi(ptr: *mut c_void)
Helper for FFI functions to call recycle.
§Safety
- The caller must ensure that
ptris valid and points to a valid object of typeSelfthat 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.