Struct ElasticRingBuffer

Source
pub struct ElasticRingBuffer<T: Clone> { /* private fields */ }
Expand description

A FIFO buffer with a fixed length that adjusts to requests that would otherwise overflow or underflow.

When an ElasticRingBuffer doesn’t have enough elements to satisfy a request, it will “stretch” the values it does have by repeating them to fill the request.

And when the buffer is getting too full (past its ideal max length), elements will be uniformly dropped to return the queue to its ideal length.

Implementations§

Source§

impl<T: Clone> ElasticRingBuffer<T>

Source

pub fn new(size: usize, value: T, ideal_max_len: usize) -> ElasticRingBuffer<T>

Create a new ElasticRingBuffer with the given size. value will be used as the default value for the queue. ideal_max_len is the threshold where the buffer will begin dropping elements during requests

Source

pub fn pop_front_slice(&mut self, values: &mut [T]) -> ElasticPopResult

Fill values with elements. See ElasticPopResult for the possible outcomes of this request.

Source

pub fn push_back_slice(&mut self, values: &[T]) -> bool

Add all values to the buffer. If there is not enough room in the queue then no values are added and the return value is false

Source

pub fn push_back(&mut self, value: T) -> bool

Add value to the end of the queue. Returns false if there is not enough room in the queue

Source

pub fn len(&self) -> usize

Returns the number of values in the buffer

Source

pub fn capacity(&self) -> usize

Returns the number of free slots in the buffer

Source

pub fn max_len(&self) -> usize

Returns the max number of values that can ever be stored in the buffer

Auto Trait Implementations§

§

impl<T> Freeze for ElasticRingBuffer<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for ElasticRingBuffer<T>
where T: RefUnwindSafe,

§

impl<T> Send for ElasticRingBuffer<T>
where T: Send,

§

impl<T> Sync for ElasticRingBuffer<T>
where T: Sync,

§

impl<T> Unpin for ElasticRingBuffer<T>
where T: Unpin,

§

impl<T> UnwindSafe for ElasticRingBuffer<T>
where T: UnwindSafe,

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.