Struct trait_based_collection::queue::Deque
source · [−]pub struct Deque<T> { /* private fields */ }
Expand description
A double-ended queue. This data structure is a combination of a Stack
and a Queue
. It
allows to push and pop elements from both ends of the queue. This data structure implements both
LIFO and FIFO. For more information, see the DequeCollection
trait.
The default behavior for the Collection
trait is to interpret the Deque
as a FIFO queue.
Examples
use trait_based_collection::{prelude::*, Deque};
let mut deque = Deque::new_default();
deque.push_back(1);
deque.push_back(2);
deque.push_front(3);
assert_eq!(deque.pop_front(), Some(3));
assert_eq!(deque.pop_front(), Some(1));
assert_eq!(deque.pop_front(), Some(2));
assert_eq!(deque.pop_front(), None);
Trait Implementations
sourceimpl<'a, T> Collection<'a, T> for Deque<T>where
T: 'a,
impl<'a, T> Collection<'a, T> for Deque<T>where
T: 'a,
sourcefn new_default() -> Self
fn new_default() -> Self
Creates a new
Collection
with a default capacity. Read moresourcefn add(&mut self, value: T)
fn add(&mut self, value: T)
Adds an item to the
Collection
. Read moresourcefn remove(&mut self) -> Option<T>
fn remove(&mut self) -> Option<T>
Removes an item from the
Collection
. Read moresourcefn peek(&self) -> Option<Self::ItemRef>
fn peek(&self) -> Option<Self::ItemRef>
Returns an immutable reference of the item that will be removed next. Read more
sourcefn peek_mut(&'a mut self) -> Option<Self::ItemMut>
fn peek_mut(&'a mut self) -> Option<Self::ItemMut>
Returns a mutable reference of the item that will be removed next. Read more
sourcefn get(&'a self, index: usize) -> Option<Self::ItemRef>
fn get(&'a self, index: usize) -> Option<Self::ItemRef>
Returns a immutable reference to the n-th item in the
Collection
. Read moresourcefn get_mut(&'a mut self, index: usize) -> Option<Self::ItemMut>
fn get_mut(&'a mut self, index: usize) -> Option<Self::ItemMut>
Returns a mutable reference to the n-th item in the
Collection
. Read moresourcefn len(&self) -> usize
fn len(&self) -> usize
Returns the number of items in the
Collection
. Read moresourcefn with_capacity(capacity: usize) -> Selfwhere
Self: Sized,
fn with_capacity(capacity: usize) -> Selfwhere
Self: Sized,
Creates a new
Collection
with a specific capacity. Read moresourcefn with_approximate_capacity(approx_capacity: usize) -> Selfwhere
Self: Sized,
fn with_approximate_capacity(approx_capacity: usize) -> Selfwhere
Self: Sized,
Creates a new
Collection
with a capacity that is at least the specified capacity. Read moresourcefn clear(&mut self)
fn clear(&mut self)
Clears all items from the
Collection
while keeping the capacity. Read moresourcefn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Checks if the
Collection
is empty. Read moresourceimpl<'a, T> DequeCollection<'a, T> for Deque<T>where
T: 'a,
impl<'a, T> DequeCollection<'a, T> for Deque<T>where
T: 'a,
sourcefn push_front(&mut self, value: T)
fn push_front(&mut self, value: T)
Pushes a new element to the front of the queue. Read more
sourcefn peek_back_mut(&'a mut self) -> Option<Self::ItemMut>
fn peek_back_mut(&'a mut self) -> Option<Self::ItemMut>
sourcefn peek_front(&'a self) -> Option<Self::ItemRef>
fn peek_front(&'a self) -> Option<Self::ItemRef>
sourceimpl<T> Extend<T> for Deque<T>
impl<T> Extend<T> for Deque<T>
sourcefn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
🔬This is a nightly-only experimental API. (
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<T> FromIterator<T> for Deque<T>
impl<T> FromIterator<T> for Deque<T>
sourcefn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
sourceimpl<'a, T> IntoIterator for &'a Deque<T>
impl<'a, T> IntoIterator for &'a Deque<T>
sourceimpl<'a, T> IntoIterator for &'a mut Deque<T>
impl<'a, T> IntoIterator for &'a mut Deque<T>
sourceimpl<T> IntoIterator for Deque<T>
impl<T> IntoIterator for Deque<T>
sourceimpl<'a, T> Iterators<'a, T> for Deque<T>where
T: 'a,
impl<'a, T> Iterators<'a, T> for Deque<T>where
T: 'a,
type ItemRef = &'a T
type ItemRef = &'a T
The type of reference the immutable iterator (
Iter
) iterates over the items in the
Collection
. The reference is only valid for the duration of the iteration. Read moretype ItemMut = &'a mut T
type ItemMut = &'a mut T
The type of mutable reference the mutable iterator (
IterMut
) iterates over the items in
the Collection
. The reference is only valid for the duration of the iteration. Read moretype IterMut = DequeIterMut<'a, T>
type IterMut = DequeIterMut<'a, T>
sourcefn iter(&'a self) -> Self::Iter
fn iter(&'a self) -> Self::Iter
Creates an immutable iterator over the items in the
Collection
without consuming them. Read moresourcefn iter_mut(&'a mut self) -> Self::IterMut
fn iter_mut(&'a mut self) -> Self::IterMut
Creates a mutable iterator over the items in the
Collection
without consuming them. Read moreAuto Trait Implementations
impl<T> RefUnwindSafe for Deque<T>where
T: RefUnwindSafe,
impl<T> !Send for Deque<T>
impl<T> !Sync for Deque<T>
impl<T> Unpin for Deque<T>
impl<T> UnwindSafe for Deque<T>where
T: RefUnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more