Struct bounded_spsc_queue::Producer[][src]

pub struct Producer<T> { /* fields omitted */ }

A handle to the queue which allows adding values onto the buffer

Methods

impl<T> Producer<T>
[src]

Push a value onto the buffer.

If the buffer is non-full, the operation will execute immediately. If the buffer is full, this method will block until the buffer is non-full. The waiting strategy is a simple spin-wait. If you do not want a spin-wait burning CPU, you should call try_push() directly and implement a different waiting strategy.

Examples

let (producer, _) = make(100);

// Block until we can push this value onto the queue
producer.push(123);

Attempt to push a value onto the buffer.

This method does not block. If the queue is not full, the value will be added to the queue and the method will return None, signifying success. If the queue is full, this method will return Some(v)``, wherev` is your original value.

Examples

let (producer, _) = make(100);

// Attempt to add this value to the queue
match producer.try push(123) {
    Some(v) => {}, // Queue full, try again later
    None => {}     // Value added to queue
}

Returns the total capacity of this queue

This value represents the total capacity of the queue when it is full. It does not represent the current usage. For that, call size().

Examples

let (producer, _) = make(100);

assert!(producer.capacity() == 100);
producer.push(123);
assert!(producer.capacity() == 100);

Returns the current size of the queue

This value represents the current size of the queue. This value can be from 0-capacity inclusive.

Examples

let (producer, _) = make(100);

assert!(producer.size() == 0);
producer.push(123);
assert!(producer.size() == 1);

Returns the available space in the queue

This value represents the number of items that can be pushed onto the queue before it becomes full.

Examples

let (producer, _) = make(100);

assert!(producer.free_space() == 100);
producer.push(123);
assert!(producer.free_space() == 99);

Trait Implementations

impl<T: Send> Send for Producer<T>
[src]

Auto Trait Implementations

impl<T> !Sync for Producer<T>