Struct RwBuffers

Source
pub struct RwBuffers { /* private fields */ }
Expand description

An instance which controls the allocation of the new buffers or reusage of already created and free instances. This instance is not thread safe. The external mutex should be used.

Implementations§

Source§

impl RwBuffers

Source

pub fn new( buf_len: usize, pre_init_cnt: usize, bufs_cnt_lim: usize, ) -> RwBufferRes<Self>

Creates new instance wshich holds the base reference in the inner storage with the capacity bounds.

§Arguments
  • buf_len - a usize length of each buffer instance in bytes where the payload is located.

  • pre_init_cnt - a usize an initial pre allocated slots with created instances.

  • bufs_cnt_lim - a maximum amount of the available slots. Determines the capacity bounds.

§Returns

A Result in form of RwBufferRes is returned with:

Source

pub fn new_unbounded(buf_len: usize, pre_init_cnt: usize) -> Self

Same as new but without any limits. Unbounded storage.

§Arguments
  • buf_len - a usize length of each buffer instance in bytes where the payload is located.

  • pre_init_cnt - a usize an initial pre allocated slots with created instances.

§Returns

Returns the instance.

Source

pub fn allocate(&mut self) -> RwBufferRes<RwBuffer>

Allocates either a new buffer or reuse the free. If the instance is created with bounds then in case if no free slots available returns error.

§Returns

A Result in form of RwBufferRes is returned with:

Source

pub fn allocate_in_place(&mut self) -> RwBuffer

Allocates a buffer “in place” i.e finds the next allocated but unused buffer and removes it from the list or alloactes new buffer without adding it to the list. Should never return error.

§Returns

A RwBuffer is returned.

Source

pub fn compact(&mut self, cnt: usize) -> usize

Retains the buffer list by removing any unused buffers as many times as set in the argument cnt. It does not guaranty than the selected amount will be freed.

§Arguments
  • cnt - how many slots to clean before exit.
§Returns

A usize is returned which indicates how many instances was removed before the cnt was reached.

Trait Implementations§

Source§

impl Debug for RwBuffers

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

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.