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]>>
impl<T, const N: usize> DequeInner<T, VecStorageInner<[MaybeUninit<T>; N]>>
Sourcepub const fn new() -> Self
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();Sourcepub const fn capacity(&self) -> usize
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.
Sourcepub const fn len(&self) -> usize
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>
impl<T, S: VecStorage<T> + ?Sized> DequeInner<T, S>
Sourcepub fn as_view(&self) -> &DequeView<T>
pub fn as_view(&self) -> &DequeView<T>
Get a reference to the Deque, erasing the N const-generic.
Sourcepub fn as_mut_view(&mut self) -> &mut DequeView<T>
pub fn as_mut_view(&mut self) -> &mut DequeView<T>
Get a mutable reference to the Deque, erasing the N const-generic.
Sourcepub fn storage_capacity(&self) -> usize
pub fn storage_capacity(&self) -> usize
Returns the maximum number of elements the deque can hold.
Sourcepub fn storage_len(&self) -> usize
pub fn storage_len(&self) -> usize
Returns the number of elements currently in the deque.
Sourcepub fn as_slices(&self) -> (&[T], &[T])
pub fn as_slices(&self) -> (&[T], &[T])
Returns a pair of slices which contain, in order, the contents of the Deque.
Sourcepub fn as_mut_slices(&mut self) -> (&mut [T], &mut [T])
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.
Sourcepub fn make_contiguous(&mut self) -> &mut [T]
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][..], &[][..]));Sourcepub fn front(&self) -> Option<&T>
pub fn front(&self) -> Option<&T>
Provides a reference to the front element, or None if the Deque is empty.
Sourcepub fn front_mut(&mut self) -> Option<&mut T>
pub fn front_mut(&mut self) -> Option<&mut T>
Provides a mutable reference to the front element, or None if the Deque is empty.
Sourcepub fn back(&self) -> Option<&T>
pub fn back(&self) -> Option<&T>
Provides a reference to the back element, or None if the Deque is empty.
Sourcepub fn back_mut(&mut self) -> Option<&mut T>
pub fn back_mut(&mut self) -> Option<&mut T>
Provides a mutable reference to the back element, or None if the Deque is empty.
Sourcepub fn pop_front(&mut self) -> Option<T>
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
Sourcepub fn pop_back(&mut self) -> Option<T>
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
Sourcepub fn push_front(&mut self, item: T) -> Result<(), T>
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
Sourcepub fn push_back(&mut self, item: T) -> Result<(), T>
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
Sourcepub unsafe fn pop_front_unchecked(&mut self) -> T
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
Sourcepub unsafe fn pop_back_unchecked(&mut self) -> T
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
Sourcepub unsafe fn push_front_unchecked(&mut self, item: T)
pub unsafe fn push_front_unchecked(&mut self, item: T)
Sourcepub unsafe fn push_back_unchecked(&mut self, item: T)
pub unsafe fn push_back_unchecked(&mut self, item: T)
Sourcepub fn get(&self, index: usize) -> Option<&T>
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.
Sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
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.
Sourcepub unsafe fn get_unchecked(&self, index: usize) -> &T
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()).
Sourcepub unsafe fn get_unchecked_mut(&mut self, index: usize) -> &mut T
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()).
Sourcepub unsafe fn swap_unchecked(&mut self, i: usize, j: usize)
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()).
Sourcepub fn swap_remove_front(&mut self, index: usize) -> Option<T>
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.
Sourcepub fn swap_remove_back(&mut self, index: usize) -> Option<T>
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.
Trait Implementations§
Source§impl<T: Debug, S: VecStorage<T> + ?Sized> Debug for DequeInner<T, S>
impl<T: Debug, S: VecStorage<T> + ?Sized> Debug for DequeInner<T, S>
Source§impl<T, S: VecStorage<T> + ?Sized> Drop for DequeInner<T, S>
impl<T, S: VecStorage<T> + ?Sized> Drop for DequeInner<T, S>
Source§impl<'a, T: 'a + Copy, S: VecStorage<T> + ?Sized> Extend<&'a T> for DequeInner<T, S>
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)
fn extend<I: IntoIterator<Item = &'a T>>(&mut self, iter: I)
§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)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.
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)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
§fn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)§fn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)Source§impl<'a, T, S: VecStorage<T> + ?Sized> IntoIterator for &'a DequeInner<T, S>
impl<'a, T, S: VecStorage<T> + ?Sized> IntoIterator for &'a DequeInner<T, S>
Source§impl<'a, T, S: VecStorage<T> + ?Sized> IntoIterator for &'a mut DequeInner<T, S>
impl<'a, T, S: VecStorage<T> + ?Sized> IntoIterator for &'a mut DequeInner<T, S>
Auto Trait Implementations§
impl<T, S> Freeze for DequeInner<T, S>where
S: Freeze + ?Sized,
impl<T, S> RefUnwindSafe for DequeInner<T, S>where
S: RefUnwindSafe + ?Sized,
T: RefUnwindSafe,
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§
§impl<T> Any for Twhere
T: 'static + ?Sized,
impl<T> Any for Twhere
T: 'static + ?Sized,
§impl<T> Borrow<T> for Twhere
T: ?Sized,
impl<T> Borrow<T> for Twhere
T: ?Sized,
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
clone_to_uninit)