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§
Source§impl<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)
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.