Producer

Struct Producer 

Source
pub struct Producer<'a, const N: usize> { /* private fields */ }
Expand description

A Producer is a smart pointer to a Buffer, which is endowed with the right to add data into the buffer. Only one Producer may exist at one time for any given buffer. The methods of a Producer are the only way to insert data into a Buffer.

Implementations§

Source§

impl<'a, const N: usize> Producer<'a, N>

Source

pub fn write<'b>(&'b mut self, target_len: usize) -> Region<'b, Self>

Return a Region for up to target_len bytes to be written into the buffer. The returned region may be shorter than target_len. The returned region has length zero if and only if the buffer is full. The returned region is guaranteed to be not longer than target_len. To write the largest possible length, set target_len = usize::MAX.

Examples found in repository?
examples/two_threads.rs (line 7)
3fn producer(mut p: fring::Producer<N>) {
4    let mut index = 'a' as u8;
5    for _ in 0..8 {
6        std::thread::sleep(std::time::Duration::from_millis(25));
7        let mut w = p.write(3);
8        for i in 0..w.len() {
9            w[i] = index;
10            index += 1;
11        }
12        println!("write \"{}\"", std::str::from_utf8(&*w).unwrap());
13    }
14}
Source

pub fn write_ref<T: ?Sized>(&mut self, item: &T) -> Result<(), ()>

If the buffer has room for *item, write it into the buffer and return Ok. Otherwise, return Err.

Source

pub fn empty_size(&self) -> usize

Return the amount of empty space currently available in the buffer. If the consumer is reading concurrently with this call, then the amount of empty space may increase, but it will not decrease below the value which is returned.

Auto Trait Implementations§

§

impl<'a, const N: usize> Freeze for Producer<'a, N>

§

impl<'a, const N: usize> !RefUnwindSafe for Producer<'a, N>

§

impl<'a, const N: usize> Send for Producer<'a, N>

§

impl<'a, const N: usize> Sync for Producer<'a, N>

§

impl<'a, const N: usize> Unpin for Producer<'a, N>

§

impl<'a, const N: usize> !UnwindSafe for Producer<'a, N>

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.