Struct std::sync::spsc_queue::QueueExperimental [-]  [+] [src]

pub struct Queue<T> {
    // some fields omitted
}

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.

Methods

impl<T: Send> Queue<T>

unsafe fn new(bound: uint) -> Queue<T>

Creates a new queue.

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.

Arguments

  • 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.

fn push(&self, t: T)

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.

fn pop(&self) -> Option<T>

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.

fn peek(&'a self) -> Option<&'a mut T>

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

Warning

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

impl<T: Send> Drop for Queue<T>

fn drop(&mut self)