[−][src]Struct tinydeque::array_deque::ArrayDeque
A deque structure that uses an array as backing storage.
Example
use tinydeque::ArrayDeque; // lots of people try to cut through the line at the DMV, and that's a dick move // if I've ever seen one. Let's make a program to keep track let mut dmv_line: ArrayDeque<[&'static str; 3]> = ArrayDeque::new(); dmv_line.push_back("John"); dmv_line.push_back("Thomas"); dmv_line.push_back("Larson"); // make sure the line isn't empty assert!(!dmv_line.is_empty()); assert_eq!(dmv_line.len(), 3); // if we push another item into the line, it will fail assert!(dmv_line.try_push_back("Carson").is_err()); // NEXT! assert_eq!(dmv_line.pop_front(), Some("John")); // we have a VIP, front of the line! dmv_line.push_front("J.J. Abrams"); assert_eq!(dmv_line.pop_front(), Some("J.J. Abrams")); // why did J.J. Abrams get to cut in front of me in line? // fuck this, I'm out of here assert_eq!(dmv_line.pop_back(), Some("Larson"));
Implementations
impl<A: Array> ArrayDeque<A>
[src]
#[must_use]pub fn new() -> Self
[src]
#[must_use]pub fn capacity() -> usize
[src]
The capacity of this ArrayDeque
. This is the maximum number of elements that can be
stored in this ArrayDeque
.
Example
assert_eq!(ArrayDeque::<[&'static str; 8]>::capacity(), 8);
pub fn len(&self) -> usize
[src]
Get the length of this ArrayDeque
.
Example
use tinydeque::ArrayDeque; // we've been hired by the Crab Patrol to find and destroy some crabs // they said we shouldn't use Rust to do this but let's do it anyways /// Representative of a single crab. #[derive(Default)] struct Crab { diameter: u16, danger_level: u16, } let mut crab_hitlist: ArrayDeque<[Crab; 10]> = ArrayDeque::new(); for i in 1..=10 { crab_hitlist.push_back(Crab { diameter: i, danger_level: 100 / i }); // small crabs are more dangerous } assert_eq!(crab_hitlist.len(), 10);
pub fn is_empty(&self) -> bool
[src]
Tell whether this ArrayDeque
is empty.
Example
let empty_deque: ArrayDeque<[(); 12]> = ArrayDeque::new(); assert!(empty_deque.is_empty());
pub fn is_full(&self) -> bool
[src]
Tell whether this ArrayDeque
is full, or its entire capacity is filled with elements.
Example
let full_deque: ArrayDeque<[i64; 12]> = (0i64..12).into_iter().collect(); assert!(full_deque.is_full());
pub fn try_push_back(&mut self, element: A::Item) -> Result<(), A::Item>
[src]
Push an element onto the back of this ArrayDeque
.
Errors
If this ArrayDeque
is full, this function returns an Err with the rejected element.
Example
use tinydeque::ArrayDeque; // we've been hired by the United Artists of America to manage their art gallery // because they're starving artists, they don't have the money to afford good hardware // thus we can only store 5 paintings at a time /// Represents a painting. #[derive(Default)] struct Painting { name: &'static str, rating: u8, } let mut painting_list: ArrayDeque<[Painting; 10]> = ArrayDeque::new(); let mut i = 0; // we have a lot of paintings named "The Jaguar" of questionable quality while let Ok(()) = painting_list.try_push_back(Painting { name: "The Jaguar", rating: 3 }) { i += 1; } assert_eq!(i, 10);
pub fn push_back(&mut self, element: A::Item)
[src]
Push an element onto the back of this ArrayDeque
.
Panics
This function will panic if the ArrayDeque
is full.
pub fn try_push_front(&mut self, element: A::Item) -> Result<(), A::Item>
[src]
Push an element onto the front of this ArrayDeque
.
Errors
If this ArrayDeque
is full, this function returns an Err with the rejected element.
pub fn push_front(&mut self, element: A::Item)
[src]
Push an element onto the front of this ArrayDeque
.
Panics
This function will panic if the ArrayDeque
is full.
pub fn pop_back(&mut self) -> Option<A::Item>
[src]
Pop an element from the back of this ArrayDeque
.
pub fn pop_front(&mut self) -> Option<A::Item>
[src]
Pop an element from the front of this ArrayDeque
.
pub fn get(&self, index: usize) -> Option<&A::Item>
[src]
Get an element at the given index.
Example
use tinydeque::ArrayDeque; let mut my_favorite_numbers = ArrayDeque::<[i32; 6]>::new(); my_favorite_numbers.push_back(5); my_favorite_numbers.push_back(50); my_favorite_numbers.push_back(33); my_favorite_numbers.push_front(48); assert_eq!(my_favorite_numbers.get(0), Some(&48)); assert_eq!(my_favorite_numbers.get(2), Some(&50)); assert_eq!(my_favorite_numbers.get(4), None);
pub fn get_mut(&mut self, index: usize) -> Option<&mut A::Item>
[src]
Get a mutable reference to an element at a given index.
pub fn is_contiguous(&self) -> bool
[src]
Tell whether or not this ArrayDeque
is contiguous.
pub fn as_slices(&self) -> (&[A::Item], &[A::Item])
[src]
Get the contents of this ArrayDeque
in the form of buffer slices.
pub fn as_mut_slices(&mut self) -> (&mut [A::Item], &mut [A::Item])
[src]
Get the contents of this ArrayDeque
in the form of mutable buffer slices.
pub fn truncate(&mut self, len: usize)
[src]
Truncate this ArrayDeque
to a certain size.
pub fn clear(&mut self)
[src]
Clear this ArrayDeque
of all elements.
pub fn iter(&self) -> Iter<'_, A>ⓘ
[src]
Create a new iterator.
pub fn append(&mut self, other: &mut Self) -> Result<(), ()>
[src]
Append another ArrayDeque
onto the back of one.
Errors
If the ArrayDeque
's contents cannot fit into this one, the Err value is returned.
pub fn back(&self) -> Option<&A::Item>
[src]
Get the back item of this ArrayDeque
.
pub fn back_mut(&mut self) -> Option<&mut A::Item>
[src]
Get a mutable reference to the back item of this ArrayDeque
.
pub fn front(&self) -> Option<&A::Item>
[src]
Get the front item of this ArrayDeque
.
pub fn front_mut(&mut self) -> Option<&mut A::Item>
[src]
Get a mutable reference to the front item of this ArrayDeque
.
pub fn contains(&self, item: &A::Item) -> bool where
A::Item: PartialEq,
[src]
A::Item: PartialEq,
Tell whether or not this deque contains an element.
Trait Implementations
impl<A: Array> Clone for ArrayDeque<A> where
A::Item: Clone,
[src]
A::Item: Clone,
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<A: Debug + Array> Debug for ArrayDeque<A>
[src]
impl<A: Array> Default for ArrayDeque<A>
[src]
impl<A: Array> Extend<<A as Array>::Item> for ArrayDeque<A>
[src]
fn extend<T>(&mut self, iter: T) where
T: IntoIterator<Item = A::Item>,
[src]
T: IntoIterator<Item = A::Item>,
fn extend_one(&mut self, item: A)
[src]
fn extend_reserve(&mut self, additional: usize)
[src]
impl<A: Array> FromIterator<<A as Array>::Item> for ArrayDeque<A>
[src]
fn from_iter<T>(iter: T) -> Self where
T: IntoIterator<Item = A::Item>,
[src]
T: IntoIterator<Item = A::Item>,
Auto Trait Implementations
impl<A> Send for ArrayDeque<A> where
A: Send,
A: Send,
impl<A> Sync for ArrayDeque<A> where
A: Sync,
A: Sync,
impl<A> Unpin for ArrayDeque<A> where
A: Unpin,
A: Unpin,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,