Skip to main content

Dealloc

Trait Dealloc 

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

Source

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:

  • ptr points to a block of memory allocated using this allocator.
  • layout describes 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§

Source

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:

  • ptr points to a block of memory allocated using this allocator.
  • layout describes 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.

Implementations on Foreign Types§

Source§

impl Dealloc for Global

Available on non-crate feature no_alloc only.
Source§

unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)

Source§

unsafe fn try_dealloc( &self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), Error>

Source§

impl Dealloc for System

Available on crate feature std and non-crate feature no_alloc only.
Source§

unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)

Source§

unsafe fn try_dealloc( &self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), Error>

Source§

impl<A: Dealloc + ?Sized> Dealloc for &A

Source§

unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)

Source§

unsafe fn try_dealloc( &self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), Self::Error>

Source§

impl<A: Dealloc + ?Sized> Dealloc for &mut A

Source§

unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)

Source§

unsafe fn try_dealloc( &self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), Self::Error>

Source§

impl<A: Dealloc + ?Sized> Dealloc for Box<A>

Source§

unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)

Source§

unsafe fn try_dealloc( &self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), Self::Error>

Source§

impl<A: Dealloc + ?Sized> Dealloc for Rc<A>

Source§

unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)

Source§

unsafe fn try_dealloc( &self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), Self::Error>

Source§

impl<A: Dealloc + ?Sized> Dealloc for Arc<A>

Source§

unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)

Source§

unsafe fn try_dealloc( &self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), Self::Error>

Source§

impl<A: DeallocMut + ?Sized> Dealloc for RefCell<A>

Source§

unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)

Source§

unsafe fn try_dealloc( &self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), Self::Error>

Source§

impl<A: DeallocMut + ?Sized> Dealloc for Mutex<A>

Source§

unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)

Source§

unsafe fn try_dealloc( &self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), Self::Error>

Source§

impl<A: DeallocMut + ?Sized> Dealloc for RwLock<A>

Source§

unsafe fn dealloc(&self, ptr: NonNull<u8>, layout: Layout)

Source§

unsafe fn try_dealloc( &self, ptr: NonNull<u8>, layout: Layout, ) -> Result<(), Self::Error>

Implementors§

Source§

impl Dealloc for CAlloc

Source§

impl Dealloc for DefaultAlloc

Available on non-crate feature no_alloc only.