Skip to main content

CheckedDealloc

Trait CheckedDealloc 

Source
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§

Source

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 via CheckedRealloc may still be supported.
  • Err(Error::Other(err)) for allocator-specific validation failures. If the alloc_mut feature is enabled, and using this method on a synchronization primitive wrapping a type which implements CheckedDeallocMut, 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".

Implementations on Foreign Types§

Source§

impl<A: CheckedDeallocMut + ?Sized> CheckedDealloc for RefCell<A>

Source§

fn checked_dealloc( &self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), <RefCell<A> as AllocDescriptor>::Error>

Implementors§