Struct bones_schema::alloc::ResizableAlloc
source · pub struct ResizableAlloc { /* private fields */ }
Expand description
A low-level memory allocation utility for creating a resizable buffer of elements of a specific layout.
The allocation has a capacity measured in the number of elements with the given Layout
that
it has room for.
Dropping a ResizableAlloc
will de-allocate it’s memory.
Implementations§
source§impl ResizableAlloc
impl ResizableAlloc
sourcepub fn new(layout: Layout) -> Self
pub fn new(layout: Layout) -> Self
Create a new ResizableAlloc
for the given memory layout. Does not actually allocate
anything yet.hing.
If the new capacity is greater, it will reallocate and extend the allocated region to be
able to fit new_capacity
items of the this ResizableAlloc
’s layout.
If the new capacity is lower, it will reallocate and remove all items
The capacity will be 0 and the pointer will be dangling.
§Panics
Panics if the provided layout is not already padded to it’s alignment.
sourcepub fn with_capacity(
layout: Layout,
capacity: usize,
) -> Result<Self, LayoutError>
pub fn with_capacity( layout: Layout, capacity: usize, ) -> Result<Self, LayoutError>
Create a new ResizableAlloc
with the given capacity.
sourcepub fn resize(&mut self, new_capacity: usize) -> Result<(), LayoutError>
pub fn resize(&mut self, new_capacity: usize) -> Result<(), LayoutError>
Resize the buffer, re-allocating it’s memory.
sourcepub fn iter(&self) -> ResizableAllocIter<'_> ⓘ
pub fn iter(&self) -> ResizableAllocIter<'_> ⓘ
Iterate over the allocation.
sourcepub fn iter_mut(&mut self) -> ResizableAllocIterMut<'_> ⓘ
pub fn iter_mut(&mut self) -> ResizableAllocIterMut<'_> ⓘ
Iterate mutably over the allocation.
Trait Implementations§
source§impl Clone for ResizableAlloc
impl Clone for ResizableAlloc
source§impl Debug for ResizableAlloc
impl Debug for ResizableAlloc
Auto Trait Implementations§
impl Freeze for ResizableAlloc
impl RefUnwindSafe for ResizableAlloc
impl !Send for ResizableAlloc
impl !Sync for ResizableAlloc
impl Unpin for ResizableAlloc
impl UnwindSafe for ResizableAlloc
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
source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
source§default unsafe fn clone_to_uninit(&self, dst: *mut T)
default unsafe fn clone_to_uninit(&self, dst: *mut T)
clone_to_uninit
)