Struct region_buffer::RegionBuffer
source · pub struct RegionBuffer<T> { /* private fields */ }
Expand description
A contiguous growable array type, allow you to obtain multiple mutable regions from it, as long these regions don’t overlap.
Implementations
sourceimpl<T> RegionBuffer<T>
impl<T> RegionBuffer<T>
sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new, empty RegionBuffer<T>
. The buffer will not allocate
until elements are pushed onto it.
sourcepub fn push(&mut self, element: T)
pub fn push(&mut self, element: T)
Appends an element to the back of a collection.
Panics
Panics if the number of elements in the buffer overflows a usize
.
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the buffer, also referred to as its ‘length’.
sourcepub fn truncate(&mut self, len: usize)
pub fn truncate(&mut self, len: usize)
Shortens the buffer, keeping the first len
elements and dropping the
rest. If len
is greater than the buffer’s current length, this has no
effect.
Note that this method has no effect on the allocated capacity of the buffer.
sourcepub fn region(&self, start: usize, end: usize) -> Slice<'_, T>
pub fn region(&self, start: usize, end: usize) -> Slice<'_, T>
Provides a mutable reference to a region in the buffer, provided that region hasn’t already been borrowed.
Panics
If the region has already been borrowed.
sourcepub fn get(&self, index: usize) -> Element<'_, T>
pub fn get(&self, index: usize) -> Element<'_, T>
Returns a single element from the buffer. The borrowing rules also apply to this single element, so you can’t get a single element from an already borrowed region and vice versa.
sourcepub fn get_mut<'a>(&self, index: usize) -> ElementMut<'a, T>
pub fn get_mut<'a>(&self, index: usize) -> ElementMut<'a, T>
Returns a single mutable element from the buffer. The borrowing rules also apply to this single element, so you can’t get a single element from an already borrowed region and vice versa.