Skip to main content

Producer

Struct Producer 

Source
pub struct Producer<'a, T: Sized, 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, T: Sized, const N: usize> Producer<'a, T, N>

Source

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

Return a Region for up to target_len elements 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<u8, 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 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.

Source§

impl<'a, T: Sized + Copy, const N: usize> Producer<'a, T, N>

Source

pub fn write_slice(&mut self, slice: &[T]) -> Option<()>

If the buffer has empty space of length at least slice.len() available, copy slice into the buffer and return Some(()). Otherwise, return None.

This is a convenience function which incurs a single copy of the slice data. For zero-copy performance, use .write() to get one or more Region views.

Auto Trait Implementations§

§

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

§

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

§

impl<'a, T, const N: usize> Freeze for Producer<'a, T, N>
where &'a Buffer<T, N>: Freeze,

§

impl<'a, T, const N: usize> Send for Producer<'a, T, N>
where &'a Buffer<T, N>: Send,

§

impl<'a, T, const N: usize> Sync for Producer<'a, T, N>
where &'a Buffer<T, N>: Sync,

§

impl<'a, T, const N: usize> Unpin for Producer<'a, T, N>
where &'a Buffer<T, N>: Unpin,

§

impl<'a, T, const N: usize> UnsafeUnpin for Producer<'a, T, N>
where &'a Buffer<T, N>: UnsafeUnpin,

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.