pub struct Queue<T: Clone> { /* private fields */ }
Expand description
A simple FIFO queue with a growable size and no limit on its capacity.
§Type parameters
T
: Any type that implements theClone
trait.
§Examples
This example uses the queue!
macro to add elements to the queue. Note
that the first element in the list of elements passed to the macro is
considered the ‘oldest’.
let mut q = queue![3isize, 4, 5];
// Add an element
assert_eq!(q.add(6), Ok(None));
// Remove some elements
assert_eq!(q.remove(), Ok(3));
assert_eq!(q.remove(), Ok(4));
// Peek at the next element scheduled for removal
assert_eq!(q.peek(), Ok(5));
// Check the queue size
assert_eq!(q.size(), 2);
Implementations§
Trait Implementations§
Source§impl<T: Clone> IsQueue<T> for Queue<T>
impl<T: Clone> IsQueue<T> for Queue<T>
Source§fn remove(&mut self) -> Result<T, &str>
fn remove(&mut self) -> Result<T, &str>
Removes an element from the queue and returns it
§Returns
Ok(T)
: The oldest element in the queueError
§Errors
Returns an error if an attempt is made to remove an element from an empty queue
§Examples
let mut q: Queue<isize> = Queue::new();
q.add(42);
assert_eq!(q.remove(), Ok(42));
assert_eq!(q.size(), 0);
Auto Trait Implementations§
impl<T> Freeze for Queue<T>
impl<T> RefUnwindSafe for Queue<T>where
T: RefUnwindSafe,
impl<T> Send for Queue<T>where
T: Send,
impl<T> Sync for Queue<T>where
T: Sync,
impl<T> Unpin for Queue<T>where
T: Unpin,
impl<T> UnwindSafe for Queue<T>where
T: UnwindSafe,
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