Struct RingBuffer

Source
pub struct RingBuffer<T> { /* private fields */ }
Expand description

An indexed multiple readable spsc ring buffer.

  • access by an absolute index.
  • a Single-Producer Single-Consumer with Multi-Reader
  • using RwLock of parking_lot
extern crate indexed_ring_buffer;
use indexed_ring_buffer::*;

let (mut p, mut c, r) = indexed_ring_buffer::<usize>(0, 5);
for i in 0..101 {
    p.push(i);
    c.shift();
}

for i in 101..106 {
    p.push(i);
}

let (start, end, data) = r.get_from(101,5).unwrap();
assert_eq!(data,vec![101,102,103,104,105]);
assert_eq!(start,101);
assert_eq!(end,105);

c.shift_to(105);
let rslt = r.get_all();
assert_eq!(rslt,None);

Ring buffer itself.

Implementations§

Source§

impl<T> RingBuffer<T>
where T: Sized + Default + Clone + Copy,

Source

pub fn new(offset: usize, size: usize) -> RingBuffer<T>

Creates a new instance of a ring buffer.

Source

pub fn get_ref(&self) -> &[MaybeUninit<T>]

Source

pub fn get_mut(&self) -> &mut [MaybeUninit<T>]

Source

pub fn is_empty(&self) -> bool

Checks if the ring buffer is empty.

Source

pub fn is_full(&self) -> bool

Checks if the ring buffer is full.

Auto Trait Implementations§

§

impl<T> !Freeze for RingBuffer<T>

§

impl<T> !RefUnwindSafe for RingBuffer<T>

§

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

§

impl<T> !Sync for RingBuffer<T>

§

impl<T> Unpin for RingBuffer<T>

§

impl<T> UnwindSafe for RingBuffer<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.