pub struct MemoryReservation { /* private fields */ }
Expand description
A MemoryReservation
tracks an individual reservation of a
number of bytes of memory in a MemoryPool
that is freed back
to the pool on drop.
The reservation can be grown or shrunk over time.
Implementations§
Source§impl MemoryReservation
impl MemoryReservation
Sourcepub fn consumer(&self) -> &MemoryConsumer
pub fn consumer(&self) -> &MemoryConsumer
Returns MemoryConsumer for this MemoryReservation
Sourcepub fn free(&mut self) -> usize
pub fn free(&mut self) -> usize
Frees all bytes from this reservation back to the underlying pool, returning the number of bytes freed.
Sourcepub fn try_shrink(&mut self, capacity: usize) -> Result<usize>
pub fn try_shrink(&mut self, capacity: usize) -> Result<usize>
Tries to free capacity
bytes from this reservation
if capacity
does not exceed Self::size
Returns new reservation size
or error if shrinking capacity is more than allocated size
Sourcepub fn try_resize(&mut self, capacity: usize) -> Result<()>
pub fn try_resize(&mut self, capacity: usize) -> Result<()>
Try to set the size of this reservation to capacity
Sourcepub fn grow(&mut self, capacity: usize)
pub fn grow(&mut self, capacity: usize)
Increase the size of this reservation by capacity
bytes
Sourcepub fn try_grow(&mut self, capacity: usize) -> Result<()>
pub fn try_grow(&mut self, capacity: usize) -> Result<()>
Try to increase the size of this reservation by capacity
bytes, returning error if there is insufficient capacity left
in the pool.
Sourcepub fn split(&mut self, capacity: usize) -> MemoryReservation
pub fn split(&mut self, capacity: usize) -> MemoryReservation
Splits off capacity
bytes from this MemoryReservation
into a new MemoryReservation
with the same
MemoryConsumer
.
This can be useful to free part of this reservation with RAAI style dropping
§Panics
Panics if capacity
exceeds Self::size
Sourcepub fn new_empty(&self) -> Self
pub fn new_empty(&self) -> Self
Returns a new empty MemoryReservation
with the same MemoryConsumer
Sourcepub fn take(&mut self) -> MemoryReservation
pub fn take(&mut self) -> MemoryReservation
Splits off all the bytes from this MemoryReservation
into
a new MemoryReservation
with the same MemoryConsumer
Trait Implementations§
Source§impl Debug for MemoryReservation
impl Debug for MemoryReservation
Auto Trait Implementations§
impl Freeze for MemoryReservation
impl !RefUnwindSafe for MemoryReservation
impl Send for MemoryReservation
impl Sync for MemoryReservation
impl Unpin for MemoryReservation
impl !UnwindSafe for MemoryReservation
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> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more