Producer

Struct Producer 

Source
pub struct Producer<T> { /* private fields */ }
Expand description

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

Implementations§

Source§

impl<T> Producer<T>

Source

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);
Source

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
}
Source

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);
Source

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);
Source

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);

Trait Implementations§

Source§

impl<T: Send> Send for Producer<T>

Auto Trait Implementations§

§

impl<T> Freeze for Producer<T>

§

impl<T> !RefUnwindSafe for Producer<T>

§

impl<T> !Sync for Producer<T>

§

impl<T> Unpin for Producer<T>

§

impl<T> !UnwindSafe for Producer<T>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.