Struct std::sync::mpsc::spsc_queue::Queue[][src]

pub struct Queue<T, ProducerAddition = (), ConsumerAddition = ()> {
    consumer: CacheAligned<Consumer<T, ConsumerAddition>>,
    producer: CacheAligned<Producer<T, ProducerAddition>>,
Expand description

The single-producer single-consumer queue. This structure is not cloneable, but it can be safely shared in an Arc if it is guaranteed that there is only one popper and one pusher touching the queue at any one point in time.


consumer: CacheAligned<Consumer<T, ConsumerAddition>>producer: CacheAligned<Producer<T, ProducerAddition>>


Creates a new queue. With given additional elements in the producer and consumer portions of the queue.

Due to the performance implications of cache-contention, we wish to keep fields used mainly by the producer on a separate cache line than those used by the consumer. Since cache lines are usually 64 bytes, it is unreasonably expensive to allocate one for small fields, so we allow users to insert additional fields into the cache lines already allocated by this for the producer and consumer.

This is unsafe as the type system doesn’t enforce a single consumer-producer relationship. It also allows the consumer to pop items while there is a peek active due to all methods having a non-mutable receiver.

  • bound - This queue implementation is implemented with a linked list, and this means that a push is always a malloc. In order to amortize this cost, an internal cache of nodes is maintained to prevent a malloc from always being necessary. This bound is the limit on the size of the cache (if desired). If the value is 0, then the cache has no bound. Otherwise, the cache will never grow larger than bound (although the queue itself could be much larger.

Pushes a new value onto this queue. Note that to use this function safely, it must be externally guaranteed that there is only one pusher.

Attempts to pop a value from this queue. Remember that to use this type safely you must ensure that there is only one popper at a time.

Attempts to peek at the head of the queue, returning None if the queue has no data currently


The reference returned is invalid if it is not used before the consumer pops the value off the queue. If the producer then pushes another value onto the queue, it will overwrite the value pointed to by the reference.

Trait Implementations

Executes the destructor for this type. 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

Performs the conversion.

Performs the conversion.

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.