[−][src]Struct rtrb::Producer
The producer side of a RingBuffer
.
Can be moved between threads,
but references from different threads are not allowed
(i.e. it is Send
but not Sync
).
Can only be created with RingBuffer::split()
(together with its counterpart, the Consumer
).
Examples
use rtrb::RingBuffer; let (producer, consumer) = RingBuffer::<f32>::new(1000).split();
Implementations
impl<T> Producer<T>
[src]
pub fn push(&mut self, value: T) -> Result<(), PushError<T>>
[src]
Attempts to push an element into the queue.
The element is moved into the ring buffer and its slot
is made available to be read by the Consumer
.
If the queue is full, the element is returned back as an error.
Examples
use rtrb::{RingBuffer, PushError}; let (mut p, c) = RingBuffer::new(1).split(); assert_eq!(p.push(10), Ok(())); assert_eq!(p.push(20), Err(PushError::Full(20)));
pub fn write_chunk(&mut self, n: usize) -> Result<WriteChunk<'_, T>, ChunkError> where
T: Copy + Default,
[src]
T: Copy + Default,
Returns n
slots (initially containing their Default
value) for writing.
If not enough slots are available, an error (containing the number of available slots) is returned.
The elements can be accessed with WriteChunk::as_mut_slices()
or
by iterating over (a &mut
to) the WriteChunk
.
The provided slots are not automatically made available
to be read by the Consumer
.
This has to be explicitly done by calling WriteChunk::commit()
,
WriteChunk::commit_iterated()
or WriteChunk::commit_all()
.
The type parameter T
has a trait bound of Copy
,
which makes sure that no destructors are called at any time
(because it implies !Drop
).
For an unsafe alternative that has no restrictions on T
,
see Producer::write_chunk_uninit()
.
Examples
See the crate-level documentation for examples.
pub fn write_chunk_uninit(
&mut self,
n: usize
) -> Result<WriteChunkUninit<'_, T>, ChunkError>
[src]
&mut self,
n: usize
) -> Result<WriteChunkUninit<'_, T>, ChunkError>
Returns n
(uninitialized) slots for writing.
If not enough slots are available, an error (containing the number of available slots) is returned.
The elements can be accessed with WriteChunkUninit::as_mut_slices()
or
by iterating over (a &mut
to) the WriteChunkUninit
.
The provided slots are not automatically made available
to be read by the Consumer
.
This has to be explicitly done by calling WriteChunkUninit::commit()
,
WriteChunkUninit::commit_iterated()
or
WriteChunkUninit::commit_all()
.
Safety
This function itself is safe, but accessing the returned slots might not be,
as well as invoking some methods of WriteChunkUninit
.
For a safe alternative that provides Default
-initialized slots,
see Producer::write_chunk()
.
pub fn slots(&self) -> usize
[src]
Returns the number of slots available for writing.
To check for a single available slot,
using Producer::is_full()
is often quicker
(because it might not have to check an atomic variable).
Examples
use rtrb::RingBuffer; let (p, c) = RingBuffer::<f32>::new(1024).split(); assert_eq!(p.slots(), 1024);
pub fn is_full(&self) -> bool
[src]
Returns true
if there are no slots available for writing.
Examples
use rtrb::RingBuffer; let (p, c) = RingBuffer::<f32>::new(1).split(); assert!(!p.is_full());
pub fn buffer(&self) -> &RingBuffer<T>
[src]
Returns a read-only reference to the ring buffer.
Trait Implementations
impl<T: Debug> Debug for Producer<T>
[src]
impl<T: Send> Send for Producer<T>
[src]
impl Write for Producer<u8>
[src]
pub fn write(&mut self, buf: &[u8]) -> Result<usize>
[src]
pub fn flush(&mut self) -> Result<()>
[src]
pub fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize, Error>
1.36.0[src]
pub fn is_write_vectored(&self) -> bool
[src]
pub fn write_all(&mut self, buf: &[u8]) -> Result<(), Error>
1.0.0[src]
pub fn write_all_vectored(
&mut self,
bufs: &mut [IoSlice<'_>]
) -> Result<(), Error>
[src]
&mut self,
bufs: &mut [IoSlice<'_>]
) -> Result<(), Error>
pub fn write_fmt(&mut self, fmt: Arguments<'_>) -> Result<(), Error>
1.0.0[src]
pub fn by_ref(&mut self) -> &mut Self
1.0.0[src]
Auto Trait Implementations
impl<T> !RefUnwindSafe for Producer<T>
impl<T> !Sync for Producer<T>
impl<T> Unpin for Producer<T>
impl<T> UnwindSafe for Producer<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,