Skip to main content

Deque

Struct Deque 

Source
pub struct Deque<T> { /* private fields */ }
Expand description

A double-ended queue backed by two Vecs.

Elements pushed to the front go into front (reversed), elements pushed to the back go into back. All four operations (push_front, push_back, pop_front, pop_back) are amortized O(1).

Implementations§

Source§

impl<T> Deque<T>

Source

pub fn new() -> Self

Create a new empty deque.

Source

pub fn len(&self) -> usize

Return the number of elements in the deque.

Source

pub fn is_empty(&self) -> bool

Return true if the deque is empty.

Source

pub fn push_front(&mut self, value: T)

Push value to the front of the deque.

Source

pub fn push_back(&mut self, value: T)

Push value to the back of the deque.

Source

pub fn pop_front(&mut self) -> Option<T>

Remove and return the front element, or None if empty.

Source

pub fn pop_back(&mut self) -> Option<T>

Remove and return the back element, or None if empty.

Source

pub fn front(&self) -> Option<&T>

Return a reference to the front element, or None if empty.

Source

pub fn back(&self) -> Option<&T>

Return a reference to the back element, or None if empty.

Trait Implementations§

Source§

impl<T> Default for Deque<T>

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<T> Freeze for Deque<T>

§

impl<T> RefUnwindSafe for Deque<T>
where T: RefUnwindSafe,

§

impl<T> Send for Deque<T>
where T: Send,

§

impl<T> Sync for Deque<T>
where T: Sync,

§

impl<T> Unpin for Deque<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Deque<T>

§

impl<T> UnwindSafe for Deque<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.