pub trait CheckedDealloc: Alloc + Dealloc {
// Required method
fn checked_dealloc(
&self,
ptr: NonNull<u8>,
layout: Layout,
) -> Result<(), <Self as AllocDescriptor>::Error>;
}Expand description
A memory allocation interface which can also perform deallocation safely.
Required Methods§
Sourcefn checked_dealloc(
&self,
ptr: NonNull<u8>,
layout: Layout,
) -> Result<(), <Self as AllocDescriptor>::Error>
fn checked_dealloc( &self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), <Self as AllocDescriptor>::Error>
Attempts to deallocate a previously allocated block after performing validity checks.
This is a noop if layout.size() == 0 or ptr is
dangling.
This method must return an error rather than silently accepting the deallocation and potentially causing undefined behavior.
§Errors
Errors are implementation-defined, refer to AllocDescriptor::Error and Error.
The standard implementations may return:
Err(Error::Unsupported)if checked deallocation is unsupported. In this case, reallocation viaCheckedReallocmay still be supported.Err(Error::Other(err))for allocator-specific validation failures. If thealloc_mutfeature is enabled, and using this method on a synchronization primitive wrapping a type which implementsCheckedDeallocMut, a generic error message will also be returned if locking the primitive fails.
This method will not return an error if ptr is dangling or if
layout.size() == 0. Instead, no action will be performed.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".