Skip to main content

RingBuffer

Struct RingBuffer 

Source
pub struct RingBuffer<'m> {
    pub dropped_frames: u64,
    pub high_water_frames: usize,
    /* private fields */
}
Expand description

A whole-frame byte ring over borrowed memory.

Fields§

§dropped_frames: u64

Frames refused or overwritten because the ring was full.

§high_water_frames: usize

Most frames ever stored at once.

Implementations§

Source§

impl<'m> RingBuffer<'m>

Source

pub fn new(buf: &'m mut [u8], format: PcmFormat) -> Result<Self>

A ring over buf for frames of format. buf must hold at least one frame; a trailing partial frame is unused.

Source

pub fn capacity_frames(&self) -> usize

Frames the ring can hold.

Source

pub fn available_frames(&self) -> usize

Frames stored right now.

Source

pub fn free_frames(&self) -> usize

Frames that can still be pushed without dropping.

Source

pub fn is_empty(&self) -> bool

True when nothing is stored.

Source

pub fn clear(&mut self)

Forget the contents (counters are kept).

Source

pub fn push(&mut self, data: &[u8]) -> Result<()>

Append whole frames. When they do not all fit, nothing is stored, the frames count as dropped and Err(Busy) comes back — the producer keeps running and the drop is on the record.

Source

pub fn push_overwrite(&mut self, data: &[u8]) -> Result<usize>

Append whole frames, discarding the oldest stored frames to make room. Returns how many frames were discarded (also added to dropped_frames). Use it when latency matters more than continuity.

Source

pub fn pop(&mut self, out: &mut [u8]) -> usize

Move up to out.len() bytes of whole frames out; returns bytes moved (0 when the ring is empty).

Source

pub fn pop_exact(&mut self, out: &mut [u8]) -> bool

Like pop but only when out.len() bytes are stored; otherwise nothing moves and false comes back. This is how a consumer waits for one whole block.

Trait Implementations§

Source§

impl<'m> Debug for RingBuffer<'m>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<'m> !UnwindSafe for RingBuffer<'m>

§

impl<'m> Freeze for RingBuffer<'m>

§

impl<'m> RefUnwindSafe for RingBuffer<'m>

§

impl<'m> Send for RingBuffer<'m>

§

impl<'m> Sync for RingBuffer<'m>

§

impl<'m> Unpin for RingBuffer<'m>

§

impl<'m> UnsafeUnpin for RingBuffer<'m>

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 = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

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.