Trait Queue

Source
pub trait Queue<T> {
    // Required methods
    fn has_elements(&self) -> bool;
    fn is_full(&self) -> bool;
    fn len(&self) -> usize;
    fn enqueue(&mut self, val: T) -> bool;
    fn push(&mut self, val: T) -> Option<T>;
    fn dequeue(&mut self) -> Option<T>;
    fn remove_first_matching<F>(&mut self, f: F) -> Option<T>
       where F: Fn(&T) -> bool;
    fn empty(&mut self);
    fn retain<F>(&mut self, f: F)
       where F: FnMut(&T) -> bool;
}

Required Methods§

Source

fn has_elements(&self) -> bool

Returns true if there are any items in the queue, false otherwise.

Source

fn is_full(&self) -> bool

Returns true if the queue is full, false otherwise.

Source

fn len(&self) -> usize

Returns how many elements are in the queue.

Source

fn enqueue(&mut self, val: T) -> bool

If the queue isn’t full, add a new element to the back of the queue. Returns whether the element was added.

Source

fn push(&mut self, val: T) -> Option<T>

Add a new element to the back of the queue, poping one from the front if necessary.

Source

fn dequeue(&mut self) -> Option<T>

Remove the element from the front of the queue.

Source

fn remove_first_matching<F>(&mut self, f: F) -> Option<T>
where F: Fn(&T) -> bool,

Remove and return one (the first) element that matches the predicate.

Source

fn empty(&mut self)

Remove all elements from the ring buffer.

Source

fn retain<F>(&mut self, f: F)
where F: FnMut(&T) -> bool,

Retains only the elements that satisfy the predicate.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl<T: Copy> Queue<T> for RingBuffer<'_, T>