Skip to main content

BufferPool

Struct BufferPool 

Source
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>

Source

pub fn builder() -> BufferPoolBuilder<V>

Source

pub fn get_buffer_size(&self) -> usize

Source

pub fn try_clear(&mut self) -> Result<(), ()>

Set all of the values back to their defaults

Source

pub fn clear(&mut self)

Set all of the values back to their defaults

§Panics

If any of the buffers have been borrowed.

Source

pub fn capacity(&self) -> usize

Return the max number of buffers

Source

pub fn change_buffer_size(&mut self, new_buffer_size: usize)

Resize the internal buffers

§Panics

If any of the buffers have been borrowed.

Source

pub fn try_change_buffer_size( &mut self, new_buffer_size: usize, ) -> Result<(), ()>

Resize the internal buffers

Source

pub fn resize_len_and_buffer(&mut self, new_len: usize, new_buffer_size: usize)

Resize both the capacity and buffers

§Panics

If any of the buffers have been borrowed

Source

pub fn is_empty(&self) -> bool

Check whether the buffer pool has no capacity

Source

pub fn reserve(&mut self, additional: usize)

Reserve an additional number of buffers

§Panics

If any of the buffers have been borrowed

Source

pub fn try_reserve(&mut self, additional: usize) -> Result<(), ()>

Reserve an additional number of buffers

Source

pub fn is_borrowed(&self) -> bool

Checks to see whether any of the internal slices have been borrowed.

Source

pub fn resize(&mut self, new_len: usize)

Change the number of internal buffers

§Panics

If any of the internal buffers have been borrowed

Source

pub fn try_resize(&mut self, new_len: usize) -> Result<(), ()>

Change the number of internal buffers

Source

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}
Source

pub fn get_space(&mut self) -> Result<BufferPoolReference<V>, ()>

Get a reference to a slice of the BufferPool.

Trait Implementations§

Source§

impl<V: Default + Clone> Default for BufferPool<V>

Source§

fn default() -> BufferPool<V>

Returns the “default value” for a type. Read more

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.