Skip to main content

BoundedRingBuffer

Struct BoundedRingBuffer 

Source
pub struct BoundedRingBuffer<T> { /* private fields */ }

Implementations§

Source§

impl<T> BoundedRingBuffer<T>
where T: Copy + Default,

Source

pub fn new() -> Self

Creates a buffer with the default capacity.

Source

pub fn with_capacity(cap: usize) -> Self

Creates a buffer with a fixed capacity.

§Panics

Panics if cap is 0.

Source

pub fn len(&self) -> usize

Returns the number of currently stored elements.

Source

pub fn capacity(&self) -> usize

Returns the maximum number of elements the buffer can store.

Source

pub fn get_idx(&self) -> usize

Returns the current read index.

Source

pub fn put_idx(&self) -> usize

Returns the current write index.

Source

pub fn is_empty(&self) -> bool

Returns true when the buffer has no readable elements.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over readable elements in logical queue order.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns a mutable iterator over readable elements in logical queue order.

Source

pub fn full(&self) -> bool

Returns true when all capacity is occupied.

Source

pub fn back(&self) -> Option<&T>

Returns a shared reference to the element at the current write index.

This does not modify buffer state.

Source

pub fn back_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the element at the current write index - 1.

This does not modify indices or length.

Source

pub fn front(&self) -> Option<&T>

Returns a shared reference to the front readable element.

Source

pub fn front_mut(&mut self) -> Option<&mut T>

Returns a mutable reference to the front readable element.

Source

pub fn enqueue(&mut self, data: T)

Enqueues a single element.

When the buffer is full, the oldest element is overwritten.

Source

pub fn dequeue(&mut self) -> Option<T>

Dequeues and returns the front element, or None if empty.

Source

pub fn advance(&mut self, size: usize)

Advances the write cursor by size slots as if size items were written.

If this exceeds available space, the oldest elements are dropped.

Source

pub fn enqueue_slice(&mut self, data: &[T])

Enqueues a slice of elements preserving order.

This is the recommended high-throughput API for streaming workloads.

If data is larger than capacity, only the last capacity elements are kept.

Source

pub fn dequeue_slice( &mut self, out_buffer: &mut [T], dequeue_size: usize, ) -> usize

Dequeues up to dequeue_size elements into out_buffer.

This is the recommended high-throughput API for draining buffered data.

Returns the number of elements actually written to out_buffer.

§Panics

Panics if out_buffer.len() < dequeue_size.

Source

pub fn as_slice(&self) -> (&[T], Option<&[T]>)

Returns readable data as one contiguous slice plus an optional wrapped slice.

Source

pub fn as_mut_slice(&mut self) -> (&mut [T], Option<&mut [T]>)

Returns mutable readable data as one contiguous slice plus an optional wrapped slice.

Source§

impl BoundedRingBuffer<u8>

Source

pub fn enqueue_u8(&mut self, value: u8)

Source

pub fn enqueue_u16(&mut self, value: u16)

Source

pub fn enqueue_u32(&mut self, value: u32)

Source

pub fn enqueue_u64(&mut self, value: u64)

Source

pub fn enqueue_u128(&mut self, value: u128)

Source

pub fn enqueue_i8(&mut self, value: i8)

Source

pub fn enqueue_i16(&mut self, value: i16)

Source

pub fn enqueue_i32(&mut self, value: i32)

Source

pub fn enqueue_i64(&mut self, value: i64)

Source

pub fn enqueue_i128(&mut self, value: i128)

Source

pub fn enqueue_isize(&mut self, value: isize)

Source

pub fn enqueue_usize(&mut self, value: usize)

Source

pub fn enqueue_f32(&mut self, value: f32)

Source

pub fn enqueue_f64(&mut self, value: f64)

Source§

impl BoundedRingBuffer<u8>

Source

pub fn dequeue_u8(&mut self) -> Option<u8>

Source

pub fn dequeue_u16(&mut self) -> Option<u16>

Source

pub fn dequeue_u32(&mut self) -> Option<u32>

Source

pub fn dequeue_u64(&mut self) -> Option<u64>

Source

pub fn dequeue_u128(&mut self) -> Option<u128>

Source

pub fn dequeue_i8(&mut self) -> Option<i8>

Source

pub fn dequeue_i16(&mut self) -> Option<i16>

Source

pub fn dequeue_i32(&mut self) -> Option<i32>

Source

pub fn dequeue_i64(&mut self) -> Option<i64>

Source

pub fn dequeue_i128(&mut self) -> Option<i128>

Source

pub fn dequeue_isize(&mut self) -> Option<isize>

Source

pub fn dequeue_usize(&mut self) -> Option<usize>

Source

pub fn dequeue_f32(&mut self) -> Option<f32>

Source

pub fn dequeue_f64(&mut self) -> Option<f64>

Source§

impl BoundedRingBuffer<u8>

Source

pub fn peek_u8(&self) -> Option<u8>

Source

pub fn peek_u16(&self) -> Option<u16>

Source

pub fn peek_u32(&self) -> Option<u32>

Source

pub fn peek_u64(&self) -> Option<u64>

Source

pub fn peek_u128(&self) -> Option<u128>

Source

pub fn peek_i8(&self) -> Option<i8>

Source

pub fn peek_i16(&self) -> Option<i16>

Source

pub fn peek_i32(&self) -> Option<i32>

Source

pub fn peek_i64(&self) -> Option<i64>

Source

pub fn peek_i128(&self) -> Option<i128>

Source

pub fn peek_usize(&self) -> Option<usize>

Source

pub fn peek_isize(&self) -> Option<isize>

Source

pub fn peek_f32(&self) -> Option<f32>

Source

pub fn peek_f64(&self) -> Option<f64>

Trait Implementations§

Source§

impl<T: Clone> Clone for BoundedRingBuffer<T>

Source§

fn clone(&self) -> BoundedRingBuffer<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Debug> Debug for BoundedRingBuffer<T>

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Default for BoundedRingBuffer<T>
where T: Copy + Default,

Source§

fn default() -> Self

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

impl<T> Display for BoundedRingBuffer<T>
where T: Display,

Source§

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

Formats the value using the given formatter. Read more
Source§

impl<T> Extend<T> for BoundedRingBuffer<T>
where T: Copy + Default,

Source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl<T> From<&[T]> for BoundedRingBuffer<T>
where T: Copy + Default,

Source§

fn from(slice: &[T]) -> Self

Converts to this type from the input type.
Source§

impl<T> From<Vec<T>> for BoundedRingBuffer<T>
where T: Copy + Default,

Source§

fn from(vec: Vec<T>) -> Self

Converts to this type from the input type.
Source§

impl<T> FromIterator<T> for BoundedRingBuffer<T>
where T: Copy + Default,

Source§

fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl<T> IntoIterator for BoundedRingBuffer<T>
where T: Copy + Default,

Source§

type Item = T

The type of the elements being iterated over.
Source§

type IntoIter = IntoIter<T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for &'a BoundedRingBuffer<T>
where T: Copy + Default,

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T> IntoIterator for &'a mut BoundedRingBuffer<T>
where T: Copy + Default,

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T> Freeze for BoundedRingBuffer<T>

§

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

§

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

§

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

§

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

§

impl<T> UnsafeUnpin for BoundedRingBuffer<T>

§

impl<T> UnwindSafe for BoundedRingBuffer<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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.