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]
impl<T> Producer<T>
pub fn push(&self, v: T)
[src]
pub fn push(&self, v: T)
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);
pub fn try_push(&self, v: T) -> Option<T>
[src]
pub fn try_push(&self, v: T) -> Option<T>
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)``, where
v` 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 }
pub fn capacity(&self) -> usize
[src]
pub fn capacity(&self) -> usize
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);
pub fn size(&self) -> usize
[src]
pub fn size(&self) -> usize
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);
pub fn free_space(&self) -> usize
[src]
pub fn free_space(&self) -> usize
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);