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>
impl<'a, const N: usize> Producer<'a, N>
Sourcepub fn write<'b>(&'b mut self, target_len: usize) -> Region<'b, Self>
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?
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}Sourcepub fn write_ref<T: ?Sized>(&mut self, item: &T) -> Result<(), ()>
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.
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.