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>
impl<'a, T: Sized, const N: usize> Producer<'a, T, N>
Sourcepub fn write<'b>(&'b mut self, target_len: usize) -> Region<'b, Self, T>
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?
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}Sourcepub fn empty_size(&self) -> usize
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>
impl<'a, T: Sized + Copy, const N: usize> Producer<'a, T, N>
Sourcepub fn write_slice(&mut self, slice: &[T]) -> Option<()>
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.