[−][src]Struct circular_queue::CircularQueue
A circular buffer-like queue.
Methods
impl<T> CircularQueue<T>
[src]
pub fn with_capacity(capacity: usize) -> Self
[src]
Constructs a new, empty CircularQueue<T>
with the requested capacity.
Panics
Panics if the requested capacity is 0.
Examples
use circular_queue::CircularQueue; let mut queue: CircularQueue<i32> = CircularQueue::with_capacity(5);
pub fn len(&self) -> usize
[src]
Returns the current number of elements in the queue.
Examples
use circular_queue::CircularQueue; let mut queue = CircularQueue::with_capacity(5); queue.push(1); queue.push(2); queue.push(3); assert_eq!(queue.len(), 3);
pub fn is_empty(&self) -> bool
[src]
Returns true
if the queue contains no elements.
Examples
use circular_queue::CircularQueue; let mut queue = CircularQueue::with_capacity(5); assert!(queue.is_empty()); queue.push(1); assert!(!queue.is_empty());
pub fn capacity(&self) -> usize
[src]
Returns the capacity of the queue.
Examples
use circular_queue::CircularQueue; let queue: CircularQueue<i32> = CircularQueue::with_capacity(5); assert_eq!(queue.capacity(), 5);
pub fn clear(&mut self)
[src]
Clears the queue.
Examples
use circular_queue::CircularQueue; let mut queue = CircularQueue::with_capacity(5); queue.push(1); queue.push(2); queue.push(3); queue.clear(); assert_eq!(queue.len(), 0);
pub fn push(&mut self, x: T)
[src]
Pushes a new element into the queue.
Once the capacity is reached, pushing new items will overwrite old ones.
Examples
use circular_queue::CircularQueue; let mut queue = CircularQueue::with_capacity(3); queue.push(1); queue.push(2); queue.push(3); queue.push(4); assert_eq!(queue.len(), 3); let mut iter = queue.iter(); assert_eq!(iter.next(), Some(&4)); assert_eq!(iter.next(), Some(&3)); assert_eq!(iter.next(), Some(&2));
pub fn iter(&self) -> Iter<T>
[src]
Returns an iterator over the queue's contents.
The iterator goes from the most recently pushed items to the oldest ones.
Examples
use circular_queue::CircularQueue; let mut queue = CircularQueue::with_capacity(3); queue.push(1); queue.push(2); queue.push(3); queue.push(4); let mut iter = queue.iter(); assert_eq!(iter.next(), Some(&4)); assert_eq!(iter.next(), Some(&3)); assert_eq!(iter.next(), Some(&2));
pub fn iter_mut(&mut self) -> IterMut<T>
[src]
Returns a mutable iterator over the queue's contents.
The iterator goes from the most recently pushed items to the oldest ones.
Examples
use circular_queue::CircularQueue; let mut queue = CircularQueue::with_capacity(3); queue.push(1); queue.push(2); queue.push(3); queue.push(4); let mut iter = queue.iter_mut(); assert_eq!(iter.next(), Some(&mut 4)); assert_eq!(iter.next(), Some(&mut 3)); assert_eq!(iter.next(), Some(&mut 2));
Trait Implementations
impl<T: Debug> Debug for CircularQueue<T>
[src]
impl<T: Clone> Clone for CircularQueue<T>
[src]
fn clone(&self) -> CircularQueue<T>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
Performs copy-assignment from source
. Read more
Auto Trait Implementations
impl<T> Unpin for CircularQueue<T> where
T: Unpin,
T: Unpin,
impl<T> Sync for CircularQueue<T> where
T: Sync,
T: Sync,
impl<T> Send for CircularQueue<T> where
T: Send,
T: Send,
Blanket Implementations
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> From<T> for T
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.