ProdEnd

Struct ProdEnd 

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

Producer endpoint for inserting data into the circular buffer. See ProdEnd::push() and ProdEnd::write().

Implementations§

Source§

impl<T> ProdEnd<T>

Source

pub fn push(&mut self, item: T) -> Option<T>

Moves a single item of into the circular buffer. Returns None on success, Some<T> containing the item if the buffer was full.

§Examples
use scbuf;

let (mut prod_ep, _) = scbuf::new_scbuf(1);
assert_eq!(prod_ep.push('a'), None);
assert_eq!(prod_ep.push('b'), Some('b'));
Source

pub fn write(&mut self, data: &mut Drain<'_, T>)

Moves n elements from data into the buffer, where n is the minimum of data.len() and the space available in the buffer. Drain is used instead of Vec to avoid possibly unnecessary shift of items in the original vector, should it not be drained completely.

§Examples
use scbuf;

let (mut prod_ep, _) = scbuf::new_scbuf(2);
let mut data = vec!['a', 'b', 'c'];
let mut drain = data.drain(..);

prod_ep.write(&mut drain);
// we can pop the leftover directly from `drain` without having it shifted
// into the first position of `data`
assert_eq!(drain.next(), Some('c'));

Auto Trait Implementations§

§

impl<T> Freeze for ProdEnd<T>

§

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

§

impl<T> Send for ProdEnd<T>

§

impl<T> Sync for ProdEnd<T>

§

impl<T> Unpin for ProdEnd<T>

§

impl<T> UnwindSafe for ProdEnd<T>
where T: RefUnwindSafe,

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.