pub struct NoopAllocator<'a>(/* private fields */);Expand description
An Allocator that does nothing.
Specifically:
allocateandallocate_zeroedwill returnErrfor any non-zero-sized allocation requestsdeallocateis a no-op, and does not require thatptrbe “currently allocated”, or fitlayout.shrink,grow, andgrow_zeroeddo not require thatptrbe “currently allocated”, or fitold_layout, and will successfully return the original pointer unchanged (with the length of the new layout) if theptris aligned for the new layout and the new layout is smaller or the same size as the old layout.
This type is usable as an Allocator when you want to borrow an existing
memory range for use in a single-allocation collection type, for example in
Box or Vec.
§Safety:
Many functions in this crate assume that impl Allocator for NoopAllocator<'_> as described above is sound, but feature(allocator_api)
is unstable and the preconditions may change.
Implementations§
Source§impl<'a> NoopAllocator<'a>
impl<'a> NoopAllocator<'a>
Trait Implementations§
Source§impl Allocator for NoopAllocator<'_>
impl Allocator for NoopAllocator<'_>
Source§fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Attempts to allocate a block of memory. Read more
Source§unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout)
unsafe fn deallocate(&self, _ptr: NonNull<u8>, _layout: Layout)
🔬This is a nightly-only experimental API. (
allocator_api)Deallocates the memory referenced by
ptr. Read moreSource§unsafe fn grow(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Attempts to extend the memory block. Read more
Source§unsafe fn grow_zeroed(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn grow_zeroed( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Behaves like
grow, but also ensures that the new contents are set to zero before being
returned. Read moreSource§unsafe fn shrink(
&self,
ptr: NonNull<u8>,
old_layout: Layout,
new_layout: Layout,
) -> Result<NonNull<[u8]>, AllocError>
unsafe fn shrink( &self, ptr: NonNull<u8>, old_layout: Layout, new_layout: Layout, ) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Attempts to shrink the memory block. Read more
Source§fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
fn allocate_zeroed(&self, layout: Layout) -> Result<NonNull<[u8]>, AllocError>
🔬This is a nightly-only experimental API. (
allocator_api)Behaves like
allocate, but also ensures that the returned memory is zero-initialized. Read moreAuto Trait Implementations§
impl<'a> Freeze for NoopAllocator<'a>
impl<'a> RefUnwindSafe for NoopAllocator<'a>
impl<'a> Send for NoopAllocator<'a>
impl<'a> Sync for NoopAllocator<'a>
impl<'a> Unpin for NoopAllocator<'a>
impl<'a> UnwindSafe for NoopAllocator<'a>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more