pub struct BufferPool<V: Default + Clone> { /* private fields */ }Expand description
A “vector of vectors” backed by a single contiguous vector. Allows for mutable borrows of non-overlapping regions.
Implementations§
Source§impl<V: Default + Clone> BufferPool<V>
impl<V: Default + Clone> BufferPool<V>
pub fn builder() -> BufferPoolBuilder<V>
pub fn get_buffer_size(&self) -> usize
Sourcepub fn change_buffer_size(&mut self, new_buffer_size: usize)
pub fn change_buffer_size(&mut self, new_buffer_size: usize)
Sourcepub fn try_change_buffer_size(
&mut self,
new_buffer_size: usize,
) -> Result<(), ()>
pub fn try_change_buffer_size( &mut self, new_buffer_size: usize, ) -> Result<(), ()>
Resize the internal buffers
Sourcepub fn resize_len_and_buffer(&mut self, new_len: usize, new_buffer_size: usize)
pub fn resize_len_and_buffer(&mut self, new_len: usize, new_buffer_size: usize)
Sourcepub fn try_reserve(&mut self, additional: usize) -> Result<(), ()>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), ()>
Reserve an additional number of buffers
Sourcepub fn is_borrowed(&self) -> bool
pub fn is_borrowed(&self) -> bool
Checks to see whether any of the internal slices have been borrowed.
Sourcepub fn try_resize(&mut self, new_len: usize) -> Result<(), ()>
pub fn try_resize(&mut self, new_len: usize) -> Result<(), ()>
Change the number of internal buffers
Sourcepub fn get_cleared_space(&mut self) -> Result<BufferPoolReference<V>, ()>
pub fn get_cleared_space(&mut self) -> Result<BufferPoolReference<V>, ()>
Get a reference to a slice of the BufferPool setting the values of the
pool back to their default value.
Examples found in repository?
examples/sum-vector.rs (line 8)
3fn main() {
4 let mut pool: BufferPool<usize> = BufferPoolBuilder::new()
5 .with_buffer_size(1024)
6 .with_capacity(100)
7 .build();
8 let mut buffer = pool.get_cleared_space().unwrap();
9 for (index, value) in buffer.as_mut().iter_mut().enumerate() {
10 *value = index;
11 }
12 let sum: usize = buffer.as_ref().iter().sum();
13 println!("Sum {}", sum);
14}Sourcepub fn get_space(&mut self) -> Result<BufferPoolReference<V>, ()>
pub fn get_space(&mut self) -> Result<BufferPoolReference<V>, ()>
Get a reference to a slice of the BufferPool.
Trait Implementations§
Auto Trait Implementations§
impl<V> Freeze for BufferPool<V>
impl<V> !RefUnwindSafe for BufferPool<V>
impl<V> !Send for BufferPool<V>
impl<V> !Sync for BufferPool<V>
impl<V> Unpin for BufferPool<V>
impl<V> UnsafeUnpin for BufferPool<V>
impl<V> !UnwindSafe for BufferPool<V>
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