pub struct Producer<T, R: RbRef>where
    R::Rb: RbWrite<T>,
{ /* private fields */ }
Expand description

Producer part of ring buffer.

Mode

It can operate in immediate (by default) or postponed mode. Mode could be switched using Self::postponed/Self::into_postponed and Self::into_immediate methods.

  • In immediate mode removed and inserted items are automatically synchronized with the other end.
  • In postponed mode synchronization occurs only when Self::sync or Self::into_immediate is called or when Self is dropped. The reason to use postponed mode is that multiple subsequent operations are performed faster due to less frequent cache synchronization.

Implementations

Creates producer from the ring buffer reference.

Safety

There must be only one producer containing the same ring buffer reference.

Returns reference to the underlying ring buffer.

Consumes self and returns underlying ring buffer reference.

Returns postponed producer that borrows Self.

Transforms Self into postponed producer.

Returns capacity of the ring buffer.

The capacity of the buffer is constant.

Checks if the ring buffer is empty.

Checks if the ring buffer is full.

The result may become irrelevant at any time because of concurring consumer activity.

The number of items stored in the buffer.

Actual number may be less than the returned value because of concurring consumer activity.

The number of remaining free places in the buffer.

Actual number may be greater than the returning value because of concurring consumer activity.

Provides a direct access to the ring buffer vacant memory. Returns a pair of slices of uninitialized memory, the second one may be empty.

Safety

Vacant memory is uninitialized. Initialized items must be put starting from the beginning of first slice. When first slice is fully filled then items must be put to the beginning of the second slice.

This method must be followed by Self::advance call with the number of items being put previously as argument. No other mutating calls allowed before that.

Moves tail counter by count places.

Safety

First count items in free space must be initialized.

Appends an item to the ring buffer.

On failure returns an Err containing the item that hasn’t been appended.

Appends items from an iterator to the ring buffer. Elements that haven’t been added to the ring buffer remain in the iterator.

Returns count of items been appended to the ring buffer.

Inserted items are committed to the ring buffer all at once in the end, e.g. when buffer is full or iterator has ended.

Appends items from slice to the ring buffer. Elements should be Copy.

Returns count of items been appended to the ring buffer.

Create new postponed producer.

Safety

There must be only one producer containing the same ring buffer reference.

Synchronize changes with the ring buffer.

Postponed producer requires manual synchronization to make pushed items visible for the consumer.

Synchronize and transform back to immediate producer.

Reads at most count bytes from Read instance and appends them to the ring buffer. If count is None then as much as possible bytes will be read.

Returns Ok(n) if read succeeded. n is number of bytes been read. n == 0 means that either read returned zero or ring buffer is full.

If read is failed then original error is returned. In this case it is guaranteed that no items was read from the reader. To achieve this we read only one contiguous slice at once. So this call may read less than remaining items in the buffer even if the reader is ready to provide more.

Trait Implementations

Write a buffer into this writer, returning how many bytes were written. Read more
Flush this output stream, ensuring that all intermediately buffered contents reach their destination. Read more
Like write, except that it writes from a slice of buffers. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Writer has an efficient write_vectored implementation. Read more
Attempts to write an entire buffer into this writer. Read more
🔬This is a nightly-only experimental API. (write_all_vectored)
Attempts to write multiple buffers into this writer. Read more
Writes a formatted string into this writer, returning any error encountered. Read more
Creates a “by reference” adapter for this instance of Write. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more
Immutably borrows from an owned value. Read more
Mutably borrows from an owned value. Read more

Returns the argument unchanged.

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

The type returned in the event of a conversion error.
Performs the conversion.
The type returned in the event of a conversion error.
Performs the conversion.