[][src]Struct bit_mask_ring_buf::BitMaskRingBufRef

pub struct BitMaskRingBufRef<'a, T: Copy + Clone + Default> { /* fields omitted */ }

A fast ring buffer implementation with cheap and safe indexing. It works by bit-masking an integer index to get the corresponding index in an array/vec whose length is a power of 2. This is best used when indexing the buffer with an isize value. Copies/reads with slices are implemented with memcpy.

This works the same as BitMaskRingBuf except it uses a reference as its data source instead of an internal Vec.

Implementations

impl<'a, T: Copy + Clone + Default> BitMaskRingBufRef<'a, T>[src]

pub fn new(slice: &'a mut [T]) -> Self[src]

Creates a new BitMaskRingBufRef with the given data.

Panics

  • This will panic if the length of the given slice is not a power of 2. It will also panic if the length is 0.

Undefined Behavior

  • Using this struct may cause undefined behavior if the given data in slice was not initialized first.

pub fn clear(&mut self)[src]

Clears all values in the ring buffer to the default value.

pub fn as_slices(&self, start: isize) -> (&[T], &[T])[src]

Returns two slices that contain the all the data in the ring buffer starting at the index start.

Returns

  • The first slice is the starting chunk of data. This will never be empty.
  • The second slice is the second contiguous chunk of data. This may or may not be empty depending if the buffer needed to wrap around to the beginning of its internal memory layout.

Undefined Behavior

  • Using this may cause undefined behavior if the given data in slice in BitMaskRingBufRef::new() was not initialized first.

pub fn as_slices_len(&self, start: isize, len: usize) -> (&[T], &[T])[src]

Returns two slices of data in the ring buffer starting at the index start and with length len.

  • start - The starting index
  • len - The length of data to read. If len is greater than the capacity of the ring buffer, then that capacity will be used instead.

Returns

  • The first slice is the starting chunk of data.
  • The second slice is the second contiguous chunk of data. This may or may not be empty depending if the buffer needed to wrap around to the beginning of its internal memory layout.

Undefined Behavior

  • Using this may cause undefined behavior if the given data in slice in BitMaskRingBufRef::new() was not initialized first.

pub fn as_mut_slices(&mut self, start: isize) -> (&mut [T], &mut [T])[src]

Returns two mutable slices that contain the all the data in the ring buffer starting at the index start.

Returns

  • The first slice is the starting chunk of data. This will never be empty.
  • The second slice is the second contiguous chunk of data. This may or may not be empty depending if the buffer needed to wrap around to the beginning of its internal memory layout.

Undefined Behavior

  • Using this may cause undefined behavior if the given data in slice in BitMaskRingBufRef::new() was not initialized first.

pub fn as_mut_slices_len(
    &mut self,
    start: isize,
    len: usize
) -> (&mut [T], &mut [T])
[src]

Returns two mutable slices of data in the ring buffer starting at the index start and with length len.

  • start - The starting index
  • len - The length of data to read. If len is greater than the capacity of the ring buffer, then that capacity will be used instead.

Returns

  • The first slice is the starting chunk of data.
  • The second slice is the second contiguous chunk of data. This may or may not be empty depending if the buffer needed to wrap around to the beginning of its internal memory layout.

Undefined Behavior

  • Using this may cause undefined behavior if the given data in slice in BitMaskRingBufRef::new() was not initialized first.

pub fn read_into(&self, slice: &mut [T], start: isize)[src]

Copies the data from the ring buffer starting from the index start into the given slice. If the length of slice is larger than the capacity of the ring buffer, then the data will be reapeated until the given slice is filled.

  • slice - This slice to copy the data into.
  • start - The index of the ring buffer to start copying from.

Undefined Behavior

  • Using this may cause undefined behavior if the given data in slice in BitMaskRingBufRef::new() was not initialized first.

pub fn write_latest(&mut self, slice: &[T], start: isize)[src]

Copies data from the given slice into the ring buffer starting from the index start. If the length of slice is larger than the capacity of the ring buffer, then only the latest data will be copied.

  • slice - This slice to copy data from.
  • start - The index of the ring buffer to start copying from.

pub fn capacity(&self) -> usize[src]

Returns the capacity of the ring buffer.

pub fn constrain(&self, i: isize) -> isize[src]

Returns the actual index of the ring buffer from the given i index. This is cheap due to the ring buffer's bit-masking algorithm.

Trait Implementations

impl<'a, T: Copy + Clone + Default> Index<isize> for BitMaskRingBufRef<'a, T>[src]

type Output = T

The returned type after indexing.

impl<'a, T: Copy + Clone + Default> IndexMut<isize> for BitMaskRingBufRef<'a, T>[src]

Auto Trait Implementations

impl<'a, T> RefUnwindSafe for BitMaskRingBufRef<'a, T> where
    T: RefUnwindSafe

impl<'a, T> Send for BitMaskRingBufRef<'a, T> where
    T: Send

impl<'a, T> Sync for BitMaskRingBufRef<'a, T> where
    T: Sync

impl<'a, T> Unpin for BitMaskRingBufRef<'a, T>

impl<'a, T> !UnwindSafe for BitMaskRingBufRef<'a, T>

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.