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

Consumer 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 consumer from the ring buffer reference.

Safety

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

Returns reference to the underlying ring buffer.

Consumes self and returns underlying ring buffer reference.

Returns postponed consumer that borrows Self.

Transforms Self into postponed consumer.

Returns capacity of the ring buffer.

The capacity of the buffer is constant.

Checks if the ring buffer is empty.

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

Checks if the ring buffer is full.

The number of items stored in the buffer.

Actual number may be greater than the returned value because of concurring producer activity.

The number of remaining free places in the buffer.

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

Provides a direct access to the ring buffer occupied memory. The difference from Self::as_slices is that this method provides slices of MaybeUninit<T>, so items may be moved out of slices.

Returns a pair of slices of stored items, the second one may be empty. Elements with lower indices in slice are older. First slice contains older items that second one.

Safety

All items are initialized. Elements must be removed starting from the beginning of first slice. When all items are removed from the first slice then items must be removed from the beginning of the second slice.

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

Provides a direct mutable access to the ring buffer occupied memory.

Same as Self::as_uninit_slices.

Safety

See Self::as_uninit_slices.

Moves head target by count places.

Safety

First count items in occupied memory must be moved out or dropped.

Returns a pair of slices which contain, in order, the contents of the ring buffer.

Returns a pair of mutable slices which contain, in order, the contents of the ring buffer.

Removes latest item from the ring buffer and returns it.

Returns None if the ring buffer is empty.

Returns an iterator that removes items one by one from the ring buffer.

Iterator provides only items that are available for consumer at the moment of pop_iter call, it will not contain new items added after it was created.

Information about removed items is commited to the buffer only when iterator is destroyed.

Returns a front-to-back iterator containing references to items in the ring buffer.

This iterator does not remove items out of the ring buffer.

Returns a front-to-back iterator that returns mutable references to items in the ring buffer.

This iterator does not remove items out of the ring buffer.

Removes at most n and at least min(n, Self::len()) items from the buffer and safely drops them.

If there is no concurring producer activity then exactly min(n, Self::len()) items are removed.

Returns the number of deleted items.

let target = HeapRb::<i32>::new(8);
let (mut prod, mut cons) = target.split();

assert_eq!(prod.push_iter(&mut (0..8)), 8);

assert_eq!(cons.skip(4), 4);
assert_eq!(cons.skip(8), 4);
assert_eq!(cons.skip(8), 0);

Removes all items from the buffer and safely drops them.

Returns the number of deleted items.

Removes first items from the ring buffer and writes them into a slice. Elements must be Copy.

On success returns count of items been removed from the ring buffer.

Create new postponed consumer.

Safety

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

Synchronize changes with the ring buffer.

Postponed consumer requires manual synchronization to make freed space visible for the producer.

Synchronize and transform back to immediate consumer.

Removes at most first count bytes from the ring buffer and writes them into a Write instance. If count is None then as much as possible bytes will be written.

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

If write is failed then original error is returned. In this case it is guaranteed that no items was written to the writer. To achieve this we write only one contiguous slice at once. So this call may write less than len items even if the writer is ready to get more.

Trait Implementations

Pull some bytes from this source into the specified buffer, returning how many bytes were read. Read more
Like read, except that it reads into a slice of buffers. Read more
🔬This is a nightly-only experimental API. (can_vector)
Determines if this Reader has an efficient read_vectored implementation. Read more
Read all bytes until EOF in this source, placing them into buf. Read more
Read all bytes until EOF in this source, appending them to buf. Read more
Read the exact number of bytes required to fill buf. Read more
🔬This is a nightly-only experimental API. (read_buf)
Pull some bytes from this source into the specified buffer. Read more
🔬This is a nightly-only experimental API. (read_buf)
Read the exact number of bytes required to fill cursor. Read more
Creates a “by reference” adaptor for this instance of Read. Read more
Transforms this Read instance to an Iterator over its bytes. Read more
Creates an adapter which will chain this stream with another. Read more
Creates an adapter which will read at most limit bytes from it. 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.