Struct rust_algorithm_club::collections::Deque
source · [−]pub struct Deque<T> { /* private fields */ }
Expand description
A double-ended queue (abbreviated to deque), for which elements can be added or remove from both back and front ends.
Underneath the hood, this Deque
uses a contiguous memory block as a ring
buffer to store values.
References:
Implementations
sourceimpl<T> Deque<T>
impl<T> Deque<T>
sourcepub fn new() -> Self
pub fn new() -> Self
Constructs a new, empty Deque<T>
.
For convenience, the deque initially allocates a region of a single T
.
sourcepub fn push_front(&mut self, elem: T)
pub fn push_front(&mut self, elem: T)
Prepends the given element value to the beginning of the container.
Parameters
elem
- The element to prepend.
Complexity
Constant.
sourcepub fn push_back(&mut self, elem: T)
pub fn push_back(&mut self, elem: T)
Appends the given element value to the end of the container.
Parameters
elem
- The element to append.
Complexity
Constant.
sourcepub fn pop_front(&mut self) -> Option<T>
pub fn pop_front(&mut self) -> Option<T>
Removes and returns the first element of the container.
If there are no elements in the container, return None
.
Complexity
Constant.
sourcepub fn pop_back(&mut self) -> Option<T>
pub fn pop_back(&mut self) -> Option<T>
Removes and returns the last element of the container.
If there are no elements in the container, return None
.
Complexity
Constant.
sourcepub fn front(&self) -> Option<&T>
pub fn front(&self) -> Option<&T>
Peeks the first element of the container.
If there are no elements in the container, return None
.
Complexity
Constant.
sourcepub fn back(&self) -> Option<&T>
pub fn back(&self) -> Option<&T>
Peeks the last element of the container.
If there are no elements in the container, return None
.
Complexity
Constant.
Trait Implementations
sourceimpl<T> IntoIterator for Deque<T>
impl<T> IntoIterator for Deque<T>
sourceimpl<'a, T> IntoIterator for &'a Deque<T>
impl<'a, T> IntoIterator for &'a Deque<T>
Auto 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 T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcepub fn borrow_mut(&mut self) -> &mut T
pub fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more