pub trait Dealloc: Alloc {
// Required method
unsafe fn try_dealloc(
&self,
ptr: NonNull<u8>,
layout: Layout,
) -> Result<(), Self::Error>;
// Provided method
unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout) { ... }
}Expand description
A memory allocation interface which can also deallocate memory.
Required Methods§
Sourceunsafe fn try_dealloc(
&self,
ptr: NonNull<u8>,
layout: Layout,
) -> Result<(), Self::Error>
unsafe fn try_dealloc( &self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), Self::Error>
Attempts to deallocate a previously allocated block. If this allocator is backed by an
allocation library which does not provide fallible deallocation operations, this may panic,
abort, or incorrectly return Ok(()).
This is a noop if layout.size() == 0.
§Safety
The caller must ensure:
ptrpoints to a block of memory allocated using this allocator.layoutdescribes exactly the same block.
§Errors
Errors are implementation-defined, refer to [Self::Error] and Error.
The standard implementations do not return any errors, as the library functions backing them are infallible.
However, if the alloc_mut feature is enabled, and using this method on a synchronization
primitive wrapping a type which implements AllocMut, an
Error::Other wrapping a generic error message will be returned if locking the primitive
fails.
Provided Methods§
Sourceunsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)
unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)
Deallocates a previously allocated block.
This is a noop if layout.size() == 0.
The default implementation simply calls try_dealloc and panics if
it returns an error.
§Safety
The caller must ensure:
ptrpoints to a block of memory allocated using this allocator.layoutdescribes exactly the same block.
§Panics
This function may panic if the try_dealloc implementation returns
an error, or the implementation chooses to panic for any other reason.