Struct arraydeque::ArrayDeque
source · pub struct ArrayDeque<T, const CAP: usize, B: Behavior = Saturating> { /* private fields */ }
Expand description
A fixed capacity ring buffer.
It can be stored directly on the stack if needed.
The “default” usage of this type as a queue is to use push_back
to add to
the queue, and pop_front
to remove from the queue. Iterating over ArrayDeque
goes front
to back.
Implementations§
source§impl<T, const CAP: usize> ArrayDeque<T, CAP, Saturating>
impl<T, const CAP: usize> ArrayDeque<T, CAP, Saturating>
sourcepub fn push_front(&mut self, element: T) -> Result<(), CapacityError<T>>
pub fn push_front(&mut self, element: T) -> Result<(), CapacityError<T>>
Add an element to the front of the deque.
Return Ok(())
if the push succeeds, or return Err(CapacityError { *element* })
if the vector is full.
§Examples
// 1 -(+)-> [_, _, _] => [1, _, _] -> Ok(())
// 2 -(+)-> [1, _, _] => [2, 1, _] -> Ok(())
// 3 -(+)-> [2, 1, _] => [3, 2, 1] -> Ok(())
// 4 -(+)-> [3, 2, 1] => [3, 2, 1] -> Err(CapacityError { element: 4 })
use arraydeque::{ArrayDeque, CapacityError};
let mut buf: ArrayDeque<_, 3> = ArrayDeque::new();
buf.push_front(1);
buf.push_front(2);
buf.push_front(3);
let overflow = buf.push_front(4);
assert_eq!(overflow, Err(CapacityError { element: 4 }));
assert_eq!(buf.back(), Some(&1));
sourcepub fn push_back(&mut self, element: T) -> Result<(), CapacityError<T>>
pub fn push_back(&mut self, element: T) -> Result<(), CapacityError<T>>
Add an element to the back of the deque.
Return Ok(())
if the push succeeds, or return Err(CapacityError { *element* })
if the vector is full.
§Examples
// [_, _, _] <-(+)- 1 => [_, _, 1] -> Ok(())
// [_, _, 1] <-(+)- 2 => [_, 1, 2] -> Ok(())
// [_, 1, 2] <-(+)- 3 => [1, 2, 3] -> Ok(())
// [1, 2, 3] <-(+)- 4 => [1, 2, 3] -> Err(CapacityError { element: 4 })
use arraydeque::{ArrayDeque, CapacityError};
let mut buf: ArrayDeque<_, 3> = ArrayDeque::new();
buf.push_back(1);
buf.push_back(2);
buf.push_back(3);
let overflow = buf.push_back(4);
assert_eq!(overflow, Err(CapacityError { element: 4 }));
assert_eq!(buf.back(), Some(&3));
sourcepub fn insert(
&mut self,
index: usize,
element: T
) -> Result<(), CapacityError<T>>
pub fn insert( &mut self, index: usize, element: T ) -> Result<(), CapacityError<T>>
Inserts an element at index
within the ArrayDeque
. Whichever
end is closer to the insertion point will be moved to make room,
and all the affected elements will be moved to new positions.
Return Ok(())
if the push succeeds, or return Err(CapacityError { *element* })
if the vector is full.
Element at index 0 is the front of the queue.
§Panics
Panics if index
is greater than ArrayDeque
’s length
§Examples
// [_, _, _] <-(#0)- 3 => [3, _, _] -> Ok(())
// [3, _, _] <-(#0)- 1 => [1, 3, _] -> Ok(())
// [1, 3, _] <-(#1)- 2 => [1, 2, 3] -> Ok(())
// [1, 2, 3] <-(#1)- 4 => [1, 2, 3] -> Err(CapacityError { element: 4 })
use arraydeque::{ArrayDeque, CapacityError};
let mut buf: ArrayDeque<_, 3> = ArrayDeque::new();
buf.insert(0, 3);
buf.insert(0, 1);
buf.insert(1, 2);
let overflow = buf.insert(1, 4);
assert_eq!(overflow, Err(CapacityError { element: 4 }));
assert_eq!(buf.back(), Some(&3));
sourcepub fn extend_front<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
pub fn extend_front<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
Extend deque from front with the contents of an iterator.
Does not extract more items than there is space for. No error occurs if there are more iterator elements.
§Examples
// [9, 8, 7] -(+)-> [_, _, _, _, _, _, _] => [7, 8, 9, _, _, _, _]
// [6, 5, 4] -(+)-> [7, 8, 9, _, _, _, _] => [4, 5, 6, 7, 8, 9, _]
// [3, 2, 1] -(+)-> [4, 5, 6, 7, 8, 9, _] => [3, 4, 5, 6, 7, 8, 9]
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 7> = ArrayDeque::new();
buf.extend_front([9, 8, 7].into_iter());
buf.extend_front([6, 5, 4].into_iter());
assert_eq!(buf.len(), 6);
// max capacity reached
buf.extend_front([3, 2, 1].into_iter());
assert_eq!(buf.len(), 7);
assert_eq!(buf, [3, 4, 5, 6, 7, 8, 9].into());
sourcepub fn extend_back<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
pub fn extend_back<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
Extend deque from back with the contents of an iterator.
Does not extract more items than there is space for. No error occurs if there are more iterator elements.
§Examples
// [_, _, _, _, _, _, _] <-(+)- [1, 2, 3] => [_, _, _, _, 1, 2, 3]
// [_, _, _, _, 1, 2, 3] <-(+)- [4, 5, 6] => [_, 1, 2, 3, 4, 5, 6]
// [_, 1, 2, 3, 4, 5, 6] <-(+)- [7, 8, 9] => [1, 2, 3, 4, 5, 6, 7]
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 7> = ArrayDeque::new();
buf.extend_back([1, 2, 3].into_iter());
buf.extend_back([4, 5, 6].into_iter());
assert_eq!(buf.len(), 6);
// max capacity reached
buf.extend_back([7, 8, 9].into_iter());
assert_eq!(buf.len(), 7);
assert_eq!(buf, [1, 2, 3, 4, 5, 6, 7].into());
source§impl<T, const CAP: usize> ArrayDeque<T, CAP, Wrapping>
impl<T, const CAP: usize> ArrayDeque<T, CAP, Wrapping>
sourcepub fn push_front(&mut self, element: T) -> Option<T>
pub fn push_front(&mut self, element: T) -> Option<T>
Add an element to the front of the deque.
Return None
if deque still has capacity, or Some(existing)
if the deque is full, where existing
is the backmost element being kicked out.
§Examples
// 1 -(+)-> [_, _, _] => [1, _, _] -> None
// 2 -(+)-> [1, _, _] => [2, 1, _] -> None
// 3 -(+)-> [2, 1, _] => [3, 2, 1] -> None
// 4 -(+)-> [3, 2, 1] => [4, 3, 2] -> Some(1)
use arraydeque::{ArrayDeque, Wrapping};
let mut buf: ArrayDeque<_, 3, Wrapping> = ArrayDeque::new();
buf.push_front(1);
buf.push_front(2);
buf.push_front(3);
let existing = buf.push_front(4);
assert_eq!(existing, Some(1));
assert_eq!(buf.back(), Some(&2));
sourcepub fn push_back(&mut self, element: T) -> Option<T>
pub fn push_back(&mut self, element: T) -> Option<T>
Appends an element to the back of a buffer
Return None
if deque still has capacity, or Some(existing)
if the deque is full, where existing
is the frontmost element being kicked out.
§Examples
// [_, _, _] <-(+)- 1 => [_, _, 1] -> None
// [_, _, 1] <-(+)- 2 => [_, 1, 2] -> None
// [_, 1, 2] <-(+)- 3 => [1, 2, 3] -> None
// [1, 2, 3] <-(+)- 4 => [2, 3, 4] -> Some(1)
use arraydeque::{ArrayDeque, Wrapping};
let mut buf: ArrayDeque<_, 3, Wrapping> = ArrayDeque::new();
buf.push_back(1);
buf.push_back(2);
buf.push_back(3);
let existing = buf.push_back(4);
assert_eq!(existing, Some(1));
assert_eq!(buf.back(), Some(&4));
sourcepub fn extend_front<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
pub fn extend_front<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
Extend deque from front with the contents of an iterator.
Extracts all items from iterator and kicks out the backmost element if necessary.
§Examples
// [9, 8, 7] -(+)-> [_, _, _, _, _, _, _] => [7, 8, 9, _, _, _, _]
// [6, 5, 4] -(+)-> [7, 8, 9, _, _, _, _] => [4, 5, 6, 7, 8, 9, _]
// [3, 2, 1] -(+)-> [4, 5, 6, 7, 8, 9, _] => [1, 2, 3, 4, 5, 6, 7]
use arraydeque::{ArrayDeque, Wrapping};
let mut buf: ArrayDeque<_, 7, Wrapping> = ArrayDeque::new();
buf.extend_front([9, 8, 7].into_iter());
buf.extend_front([6, 5, 4].into_iter());
assert_eq!(buf.len(), 6);
// max capacity reached
buf.extend_front([3, 2, 1].into_iter());
assert_eq!(buf.len(), 7);
assert_eq!(buf, [1, 2, 3, 4, 5, 6, 7].into());
sourcepub fn extend_back<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
pub fn extend_back<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
Extend deque from back with the contents of an iterator.
Extracts all items from iterator and kicks out the frontmost element if necessary.
§Examples
// [_, _, _, _, _, _, _] <-(+)- [1, 2, 3] => [_, _, _, _, 1, 2, 3]
// [_, _, _, _, 1, 2, 3] <-(+)- [4, 5, 6] => [_, 1, 2, 3, 4, 5, 6]
// [_, 1, 2, 3, 4, 5, 6] <-(+)- [7, 8, 9] => [3, 4, 5, 6, 7, 8, 9]
use arraydeque::{ArrayDeque, Wrapping};
let mut buf: ArrayDeque<_, 7, Wrapping> = ArrayDeque::new();
buf.extend_back([1, 2, 3].into_iter());
buf.extend_back([4, 5, 6].into_iter());
assert_eq!(buf.len(), 6);
// max capacity reached
buf.extend_back([7, 8, 9].into_iter());
assert_eq!(buf.len(), 7);
assert_eq!(buf, [3, 4, 5, 6, 7, 8, 9].into());
source§impl<T, const CAP: usize, B: Behavior> ArrayDeque<T, CAP, B>
impl<T, const CAP: usize, B: Behavior> ArrayDeque<T, CAP, B>
sourcepub const fn new() -> ArrayDeque<T, CAP, B>
pub const fn new() -> ArrayDeque<T, CAP, B>
Creates an empty ArrayDeque
.
§Examples
use arraydeque::ArrayDeque;
let buf: ArrayDeque<usize, 2> = ArrayDeque::new();
sourcepub const fn capacity(&self) -> usize
pub const fn capacity(&self) -> usize
Return the capacity of the ArrayDeque
.
§Examples
use arraydeque::ArrayDeque;
let buf: ArrayDeque<usize, 2> = ArrayDeque::new();
assert_eq!(buf.capacity(), 2);
sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of elements in the ArrayDeque
.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 1> = ArrayDeque::new();
assert_eq!(buf.len(), 0);
buf.push_back(1);
assert_eq!(buf.len(), 1);
sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the buffer contains no elements
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 1> = ArrayDeque::new();
assert!(buf.is_empty());
buf.push_back(1);
assert!(!buf.is_empty());
sourcepub fn as_uninit_slice(&self) -> &[MaybeUninit<T>]
pub fn as_uninit_slice(&self) -> &[MaybeUninit<T>]
Entire capacity of the underlying storage
sourcepub fn as_uninit_slice_mut(&mut self) -> &mut [MaybeUninit<T>]
pub fn as_uninit_slice_mut(&mut self) -> &mut [MaybeUninit<T>]
Entire capacity of the underlying storage
sourcepub fn is_full(&self) -> bool
pub fn is_full(&self) -> bool
Returns true if the buffer is full.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 1> = ArrayDeque::new();
assert!(!buf.is_full());
buf.push_back(1);
assert!(buf.is_full());
sourcepub fn contains(&self, x: &T) -> boolwhere
T: PartialEq<T>,
pub fn contains(&self, x: &T) -> boolwhere
T: PartialEq<T>,
Returns true
if the ArrayDeque
contains an element equal to the
given value.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 2> = ArrayDeque::new();
buf.push_back(1);
buf.push_back(2);
assert_eq!(buf.contains(&1), true);
assert_eq!(buf.contains(&3), false);
sourcepub fn front(&self) -> Option<&T>
pub fn front(&self) -> Option<&T>
Provides a reference to the front element, or None
if the sequence is
empty.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 2> = ArrayDeque::new();
assert_eq!(buf.front(), None);
buf.push_back(1);
buf.push_back(2);
assert_eq!(buf.front(), Some(&1));
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
sequence is empty.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 2> = ArrayDeque::new();
assert_eq!(buf.front_mut(), None);
buf.push_back(1);
buf.push_back(2);
assert_eq!(buf.front_mut(), Some(&mut 1));
sourcepub fn back(&self) -> Option<&T>
pub fn back(&self) -> Option<&T>
Provides a reference to the back element, or None
if the sequence is
empty.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 2> = ArrayDeque::new();
buf.push_back(1);
buf.push_back(2);
assert_eq!(buf.back(), Some(&2));
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
sequence is empty.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 2> = ArrayDeque::new();
buf.push_back(1);
buf.push_back(2);
assert_eq!(buf.back_mut(), Some(&mut 2));
sourcepub fn get(&self, index: usize) -> Option<&T>
pub fn get(&self, index: usize) -> Option<&T>
Retrieves an element in the ArrayDeque
by index.
Element at index 0 is the front of the queue.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 3> = ArrayDeque::new();
buf.push_back(0);
buf.push_back(1);
buf.push_back(2);
assert_eq!(buf.get(1), Some(&1));
sourcepub fn get_mut(&mut self, index: usize) -> Option<&mut T>
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
Retrieves an element in the ArrayDeque
mutably by index.
Element at index 0 is the front of the queue.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 3> = ArrayDeque::new();
buf.push_back(0);
buf.push_back(1);
buf.push_back(2);
assert_eq!(buf.get_mut(1), Some(&mut 1));
sourcepub fn iter(&self) -> Iter<'_, T> ⓘ
pub fn iter(&self) -> Iter<'_, T> ⓘ
Returns a front-to-back iterator.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 3> = ArrayDeque::new();
buf.push_back(0);
buf.push_back(1);
buf.push_back(2);
let expected = [0, 1, 2];
assert!(buf.iter().eq(expected.iter()));
sourcepub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
pub fn iter_mut(&mut self) -> IterMut<'_, T> ⓘ
Returns a front-to-back iterator that returns mutable references.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<usize, 3> = ArrayDeque::new();
buf.push_back(0);
buf.push_back(1);
buf.push_back(2);
let mut expected = [0, 1, 2];
assert!(buf.iter_mut().eq(expected.iter_mut()));
sourcepub fn linearize(&mut self)
pub fn linearize(&mut self)
Make the buffer contiguous
The linearization may be required when interacting with external interfaces requiring contiguous slices.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<isize, 10> = ArrayDeque::new();
buf.extend_back([1, 2, 3]);
buf.extend_front([-1, -2, -3]);
buf.linearize();
assert_eq!(buf.as_slices().1.len(), 0);
§Complexity
Takes O(len())
time and no extra space.
sourcepub fn pop_front(&mut self) -> Option<T>
pub fn pop_front(&mut self) -> Option<T>
Removes the first element and returns it, or None
if the sequence is
empty.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 2> = ArrayDeque::new();
buf.push_back(1);
buf.push_back(2);
assert_eq!(buf.pop_front(), Some(1));
assert_eq!(buf.pop_front(), Some(2));
assert_eq!(buf.pop_front(), None);
sourcepub fn pop_back(&mut self) -> Option<T>
pub fn pop_back(&mut self) -> Option<T>
Removes the last element from a buffer and returns it, or None
if
it is empty.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 2> = ArrayDeque::new();
assert_eq!(buf.pop_back(), None);
buf.push_back(1);
buf.push_back(2);
assert_eq!(buf.pop_back(), Some(2));
assert_eq!(buf.pop_back(), Some(1));
sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the buffer, removing all values.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 1> = ArrayDeque::new();
buf.push_back(1);
buf.clear();
assert!(buf.is_empty());
sourcepub fn drain<R>(&mut self, range: R) -> Drain<'_, T, CAP, B> ⓘwhere
R: RangeArgument<usize>,
pub fn drain<R>(&mut self, range: R) -> Drain<'_, T, CAP, B> ⓘwhere
R: RangeArgument<usize>,
Create a draining iterator that removes the specified range in the
ArrayDeque
and yields the removed items.
Note 1: The element range is removed even if the iterator is not consumed until the end.
Note 2: It is unspecified how many elements are removed from the deque,
if the Drain
value is not dropped, but the borrow it holds expires
(eg. due to mem::forget).
§Panics
Panics if the starting point is greater than the end point or if the end point is greater than the length of the deque.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 3> = ArrayDeque::new();
buf.push_back(0);
buf.push_back(1);
buf.push_back(2);
{
let drain = buf.drain(2..);
assert!([2].into_iter().eq(drain));
}
{
let iter = buf.iter();
assert!([0, 1].iter().eq(iter));
}
// A full range clears all contents
buf.drain(..);
assert!(buf.is_empty());
sourcepub fn swap(&mut self, i: usize, j: usize)
pub fn swap(&mut self, i: usize, j: usize)
Swaps elements at indices i
and j
.
i
and j
may be equal.
Fails if there is no element with either index.
Element at index 0 is the front of the queue.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 3> = ArrayDeque::new();
buf.push_back(0);
buf.push_back(1);
buf.push_back(2);
buf.swap(0, 2);
assert_eq!(buf, [2, 1, 0].into());
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 ArrayDeque
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.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 3> = ArrayDeque::new();
assert_eq!(buf.swap_remove_back(0), None);
buf.push_back(0);
buf.push_back(1);
buf.push_back(2);
assert_eq!(buf.swap_remove_back(0), Some(0));
assert_eq!(buf, [2, 1].into());
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 ArrayDeque
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.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 3> = ArrayDeque::new();
assert_eq!(buf.swap_remove_back(0), None);
buf.push_back(0);
buf.push_back(1);
buf.push_back(2);
assert_eq!(buf.swap_remove_front(2), Some(2));
assert_eq!(buf, [1, 0].into());
sourcepub fn remove(&mut self, index: usize) -> Option<T>
pub fn remove(&mut self, index: usize) -> Option<T>
Removes and returns the element at index
from the ArrayDeque
.
Whichever end is closer to the removal point will be moved to make
room, and all the affected elements will be moved to new positions.
Returns None
if index
is out of bounds.
Element at index 0 is the front of the queue.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 3> = ArrayDeque::new();
buf.push_back(0);
buf.push_back(1);
buf.push_back(2);
assert_eq!(buf.remove(1), Some(1));
assert_eq!(buf, [0, 2].into());
sourcepub fn split_off(&mut self, at: usize) -> Self
pub fn split_off(&mut self, at: usize) -> Self
Splits the collection into two at the given index.
Returns a newly allocated Self
. self
contains elements [0, at)
,
and the returned Self
contains elements [at, len)
.
Element at index 0 is the front of the queue.
§Panics
Panics if at > len
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 3> = ArrayDeque::new();
buf.push_back(0);
buf.push_back(1);
buf.push_back(2);
// buf = [0], buf2 = [1, 2]
let buf2 = buf.split_off(1);
assert_eq!(buf.len(), 1);
assert_eq!(buf2.len(), 2);
sourcepub fn retain<F>(&mut self, f: F)where
F: FnMut(&T) -> bool,
pub fn retain<F>(&mut self, f: F)where
F: FnMut(&T) -> bool,
Retains only the elements specified by the predicate.
In other words, remove all elements e
such that f(&e)
returns false.
This method operates in place and preserves the order of the retained
elements.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 4> = ArrayDeque::new();
buf.extend_back(0..4);
buf.retain(|&x| x % 2 == 0);
assert_eq!(buf, [0, 2].into());
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
ArrayDeque
.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 7> = ArrayDeque::new();
buf.push_back(0);
buf.push_back(1);
assert_eq!(buf.as_slices(), (&[0, 1][..], &[][..]));
buf.push_front(2);
assert_eq!(buf.as_slices(), (&[2][..], &[0, 1][..]));
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 slices which contain, in order, the contents of the
ArrayDeque
.
§Examples
use arraydeque::ArrayDeque;
let mut buf: ArrayDeque<_, 7> = ArrayDeque::new();
buf.push_back(0);
buf.push_back(1);
assert_eq!(buf.as_mut_slices(), (&mut [0, 1][..], &mut[][..]));
buf.push_front(2);
assert_eq!(buf.as_mut_slices(), (&mut[2][..], &mut[0, 1][..]));
Trait Implementations§
source§impl<T, const CAP: usize> Clone for ArrayDeque<T, CAP, Saturating>where
T: Clone,
impl<T, const CAP: usize> Clone for ArrayDeque<T, CAP, Saturating>where
T: Clone,
source§impl<T, const CAP: usize> Clone for ArrayDeque<T, CAP, Wrapping>where
T: Clone,
impl<T, const CAP: usize> Clone for ArrayDeque<T, CAP, Wrapping>where
T: Clone,
source§impl<T, const CAP: usize, B: Behavior> Debug for ArrayDeque<T, CAP, B>where
T: Debug,
impl<T, const CAP: usize, B: Behavior> Debug for ArrayDeque<T, CAP, B>where
T: Debug,
source§impl<T, const CAP: usize, B: Behavior> Default for ArrayDeque<T, CAP, B>
impl<T, const CAP: usize, B: Behavior> Default for ArrayDeque<T, CAP, B>
source§impl<T, const CAP: usize, B: Behavior> Drop for ArrayDeque<T, CAP, B>
impl<T, const CAP: usize, B: Behavior> Drop for ArrayDeque<T, CAP, B>
source§impl<T, const CAP: usize> Extend<T> for ArrayDeque<T, CAP, Saturating>
impl<T, const CAP: usize> Extend<T> for ArrayDeque<T, CAP, Saturating>
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
§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, const CAP: usize> Extend<T> for ArrayDeque<T, CAP, Wrapping>
impl<T, const CAP: usize> Extend<T> for ArrayDeque<T, CAP, Wrapping>
source§fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = T>,
§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
)