DequeInner

Struct DequeInner 

Source
pub struct DequeInner<T, S: VecStorage<T> + ?Sized> { /* private fields */ }
Expand description

Base struct for Deque and DequeView, generic over the VecStorage.

In most cases you should use Deque or DequeView directly. Only use this struct if you want to write code that’s generic over both.

Implementations§

Source§

impl<T, const N: usize> DequeInner<T, VecStorageInner<[MaybeUninit<T>; N]>>

Source

pub const fn new() -> Self

Constructs a new, empty deque with a fixed capacity of N

§Examples
use heapless::Deque;

// allocate the deque on the stack
let mut x: Deque<u8, 16> = Deque::new();

// allocate the deque in a static variable
static mut X: Deque<u8, 16> = Deque::new();
Source

pub const fn capacity(&self) -> usize

Returns the maximum number of elements the deque can hold.

This method is not available on a DequeView, use storage_capacity instead.

Source

pub const fn len(&self) -> usize

Returns the number of elements currently in the deque.

This method is not available on a DequeView, use storage_len instead.

Source§

impl<T, S: VecStorage<T> + ?Sized> DequeInner<T, S>

Source

pub fn as_view(&self) -> &DequeView<T>

Get a reference to the Deque, erasing the N const-generic.

Source

pub fn as_mut_view(&mut self) -> &mut DequeView<T>

Get a mutable reference to the Deque, erasing the N const-generic.

Source

pub fn storage_capacity(&self) -> usize

Returns the maximum number of elements the deque can hold.

Source

pub fn storage_len(&self) -> usize

Returns the number of elements currently in the deque.

Source

pub fn clear(&mut self)

Clears the deque, removing all values.

Source

pub fn is_empty(&self) -> bool

Returns whether the deque is empty.

Source

pub fn is_full(&self) -> bool

Returns whether the deque is full (i.e. if len() == capacity().

Source

pub fn as_slices(&self) -> (&[T], &[T])

Returns a pair of slices which contain, in order, the contents of the Deque.

Source

pub fn as_mut_slices(&mut self) -> (&mut [T], &mut [T])

Returns a pair of mutable slices which contain, in order, the contents of the Deque.

Source

pub fn make_contiguous(&mut self) -> &mut [T]

Rearranges the internal storage of the Deque to make it into a contiguous slice, which is returned.

This does not change the order of the elements in the deque. The returned slice can then be used to perform contiguous slice operations on the deque.

After calling this method, subsequent as_slices and as_mut_slices calls will return a single contiguous slice.

§Examples

Sorting a deque:

use heapless::Deque;

let mut buf = Deque::<_, 4>::new();
buf.push_back(2).unwrap();
buf.push_back(1).unwrap();
buf.push_back(3).unwrap();

// Sort the deque
buf.make_contiguous().sort();
assert_eq!(buf.as_slices(), (&[1, 2, 3][..], &[][..]));

// Sort the deque in reverse
buf.make_contiguous().sort_by(|a, b| b.cmp(a));
assert_eq!(buf.as_slices(), (&[3, 2, 1][..], &[][..]));
Source

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

Provides a reference to the front element, or None if the Deque is empty.

Source

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

Provides a mutable reference to the front element, or None if the Deque is empty.

Source

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

Provides a reference to the back element, or None if the Deque is empty.

Source

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

Provides a mutable reference to the back element, or None if the Deque is empty.

Source

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

Removes the item from the front of the deque and returns it, or None if it’s empty

Source

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

Removes the item from the back of the deque and returns it, or None if it’s empty

Source

pub fn push_front(&mut self, item: T) -> Result<(), T>

Appends an item to the front of the deque

Returns back the item if the deque is full

Source

pub fn push_back(&mut self, item: T) -> Result<(), T>

Appends an item to the back of the deque

Returns back the item if the deque is full

Source

pub unsafe fn pop_front_unchecked(&mut self) -> T

Removes an item from the front of the deque and returns it, without checking that the deque is not empty

§Safety

It’s undefined behavior to call this on an empty deque

Source

pub unsafe fn pop_back_unchecked(&mut self) -> T

Removes an item from the back of the deque and returns it, without checking that the deque is not empty

§Safety

It’s undefined behavior to call this on an empty deque

Source

pub unsafe fn push_front_unchecked(&mut self, item: T)

Appends an item to the front of the deque

§Safety

This assumes the deque is not full.

Source

pub unsafe fn push_back_unchecked(&mut self, item: T)

Appends an item to the back of the deque

§Safety

This assumes the deque is not full.

Source

pub fn get(&self, index: usize) -> Option<&T>

Returns a reference to the element at the given index.

Index 0 is the front of the Deque.

Source

pub fn get_mut(&mut self, index: usize) -> Option<&mut T>

Returns a mutable reference to the element at the given index.

Index 0 is the front of the Deque.

Source

pub unsafe fn get_unchecked(&self, index: usize) -> &T

Returns a reference to the element at the given index without checking if it exists.

§Safety

The element at the given index must exist (i.e. index < self.len()).

Source

pub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T

Returns a mutable reference to the element at the given index without checking if it exists.

§Safety

The element at the given index must exist (i.e. index < self.len()).

Source

pub fn swap(&mut self, i: usize, j: usize)

Swaps elements at indices i and j.

§Panics

Panics if either i or j are out of bounds.

Source

pub unsafe fn swap_unchecked(&mut self, i: usize, j: usize)

Swaps elements at indices i and j without checking that they exist.

§Safety

Elements at indexes i and j must exist (i.e. i < self.len() and j < self.len()).

Source

pub fn swap_remove_front(&mut self, index: usize) -> Option<T>

Removes an element from anywhere in the deque and returns it, replacing it with the first element.

This does not preserve ordering, but is O(1).

Returns None if index is out of bounds.

Element at index 0 is the front of the queue.

Source

pub fn swap_remove_back(&mut self, index: usize) -> Option<T>

Removes an element from anywhere in the deque and returns it, replacing it with the last element.

This does not preserve ordering, but is O(1).

Returns None if index is out of bounds.

Element at index 0 is the front of the queue.

Source

pub fn iter(&self) -> Iter<'_, T>

Returns an iterator over the deque.

Source

pub fn iter_mut(&mut self) -> IterMut<'_, T>

Returns an iterator that allows modifying each value.

Trait Implementations§

Source§

impl<T: Debug, S: VecStorage<T> + ?Sized> Debug for DequeInner<T, S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, S: VecStorage<T> + ?Sized> Drop for DequeInner<T, S>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

impl<'a, T: 'a + Copy, S: VecStorage<T> + ?Sized> Extend<&'a T> for DequeInner<T, S>

Source§

fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

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
Source§

impl<T, S: VecStorage<T> + ?Sized> Extend<T> for DequeInner<T, S>

As with the standard library’s VecDeque, items are added via push_back.

Source§

fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

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
Source§

impl<'a, T, S: VecStorage<T> + ?Sized> IntoIterator for &'a DequeInner<T, S>

Source§

type Item = &'a T

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl<'a, T, S: VecStorage<T> + ?Sized> IntoIterator for &'a mut DequeInner<T, S>

Source§

type Item = &'a mut T

The type of the elements being iterated over.
Source§

type IntoIter = IterMut<'a, T>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

Auto Trait Implementations§

§

impl<T, S> Freeze for DequeInner<T, S>
where S: Freeze + ?Sized,

§

impl<T, S> RefUnwindSafe for DequeInner<T, S>

§

impl<T, S> Send for DequeInner<T, S>
where S: Send + ?Sized, T: Send,

§

impl<T, S> Sync for DequeInner<T, S>
where S: Sync + ?Sized, T: Sync,

§

impl<T, S> Unpin for DequeInner<T, S>
where S: Unpin + ?Sized, T: Unpin,

§

impl<T, S> UnwindSafe for DequeInner<T, S>
where S: UnwindSafe + ?Sized, 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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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.