pub struct Producer<T> { /* private fields */ }Expand description
A producer for the FastQueue. This is used to send elements to the queue.
Implementations§
Source§impl<T> Producer<T>
A producer for the FastQueue. This is used to send elements to the queue.
impl<T> Producer<T>
A producer for the FastQueue. This is used to send elements to the queue.
Sourcepub fn push(&mut self, value: T) -> Result<(), T>
pub fn push(&mut self, value: T) -> Result<(), T>
Pushes a value into the queue. Returns Ok(()) on success or Err(T) if the queue is full.
§Example
use fq::FastQueue;
let (mut producer, mut consumer) = FastQueue::new(2);
producer.push(42).unwrap();
assert_eq!(consumer.pop(), Some(42));Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the current number of elements in the queue (may be stale)
This function may return stale data when holding a lock on the queue.
§Example
use fq::FastQueue;
let (mut producer, mut consumer) = FastQueue::new(2);
assert_eq!(consumer.len(), 0);
producer.push(42).unwrap();
assert_eq!(consumer.len(), 1);Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Checks if the queue is empty (may be stale). This function will return true if the queue is empty, and false otherwise.
This function will return stale data when holding a lock on the queue.
§Example
use fq::FastQueue;
let (mut producer, mut consumer) = FastQueue::new(2);
assert!(consumer.is_empty());
producer.push(42).unwrap();
assert!(!consumer.is_empty());Sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Checks if the queue is full (may be stale). This function will return true if the queue is full, and false otherwise.
§Example
use fq::FastQueue;
let (mut producer, mut consumer) = FastQueue::<usize>::new(2);
producer.push(42).unwrap(); // ⚠️ Prefer handling the error over using unwrap()
assert_eq!(producer.is_full(), false);
producer.push(43).unwrap();
assert_eq!(producer.is_full(), true);Trait Implementations§
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>where
T: Unpin,
impl<T> UnsafeUnpin for Producer<T>
impl<T> UnwindSafe for Producer<T>where
T: UnwindSafe + RefUnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more