Struct SliceRingImpl

Source
pub struct SliceRingImpl<T> {
    pub first_readable: usize,
    pub next_writable: usize,
    pub buf: Vec<T>,
}
Expand description

readable area starts at first_readable and goes until next_writable. next_writable is one after the last readable and not readable.

R = first_readable
W = next_writable
o = occupied (len)
. = free

 R             W
[o o o o o o o . . . .]

Fields§

§first_readable: usize

index into buf of the first element that could be read. only gets incremented, never decremented. wraps around.

§next_writable: usize

index into buf where the next element could we written. only gets incremented, never decremented. wraps around at buf.cap().

§buf: Vec<T>

Implementations§

Source§

impl<T> SliceRingImpl<T>

ringbuffer focused on and optimized for operating on slices of values: appending to the back, reading from the front and dropping from the front. which is much faster. TODO call SliceRingImplImpl

Source

pub fn new() -> SliceRingImpl<T>

creates an empty SliceRingImpl.

Source

pub fn with_capacity(n: usize) -> SliceRingImpl<T>

creates an empty SliceRingImpl with space for at least n elements.

Source

pub fn cap(&self) -> usize

Source

pub fn capacity(&self) -> usize

Source

pub fn is_continuous(&self) -> bool

Source

pub fn len(&self) -> usize

returns the number of elements in the SliceRingImpl

Source

pub fn wrap_add(&self, index: usize, addend: usize) -> usize

returns the index into the underlying buffer for a given logical element index + addend

Source

pub unsafe fn handle_cap_increase(&mut self, old_cap: usize)

this is the most complex part Frobs the head and tail sections around to handle the fact that we just reallocated. Unsafe because it trusts old_cap.

Trait Implementations§

Source§

impl<T: Clone> SliceRing<T> for SliceRingImpl<T>

Source§

fn push_many_back(&mut self, input: &[T])

appends values to the back of this ring.
Source§

fn drop_many_front(&mut self, count: usize) -> usize

removes count elements from the front of this ring. returns how many elements were removed. returns less than count if less elements are present in this ring.
Source§

fn read_many_front(&self, output: &mut [T]) -> usize

copies the first output.len() elements present in this ring into output. returns how many elements were copied. returns less than output.len() if there are less elements present in this ring.

Auto Trait Implementations§

§

impl<T> Freeze for SliceRingImpl<T>

§

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

§

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

§

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

§

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

§

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