[−][src]Struct bounded_vec_deque::BoundedVecDeque
A double-ended queue|ringbuffer with an upper bound on its length.
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. extend()
, append()
, and from_iter()
push
onto the back in this manner, and iterating over BoundedVecDeque
goes front to back.
This type is a wrapper around VecDeque
. Almost all of its associated functions delegate to
VecDeque
's (after enforcing the length bound).
Capacity and reallocation
At the time of writing, VecDeque
behaves as follows:
- It always keeps its capacity at one less than a power of two.
- It always keeps an allocation (unlike e.g.
Vec
, wherenew()
does not allocate and the capacity can be reduced to zero). - Its
reserve_exact()
is just an alias forreserve()
.
This behavior is inherited by BoundedVecDeque
(because it is merely a wrapper). It is not
documented by VecDeque
(and is thus subject to change), but has been noted here because it
may be surprising or undesirable.
Users may wish to use maximum lengths that are one less than powers of two to prevent (at least
with the current VecDeque
reallocation strategy) “wasted space” caused by the capacity
growing beyond the maximum length.
Methods
impl<T> BoundedVecDeque<T>
[src]
pub fn new(max_len: usize) -> Self
[src]
Creates a new, empty BoundedVecDeque
.
The capacity is set to the length limit (as a result, no reallocations will be necessary unless the length limit is later raised).
Examples
use ::bounded_vec_deque::BoundedVecDeque; let deque: BoundedVecDeque<i32> = BoundedVecDeque::new(255); assert!(deque.is_empty()); assert_eq!(deque.max_len(), 255); assert!(deque.capacity() >= 255);
pub fn with_capacity(capacity: usize, max_len: usize) -> Self
[src]
Creates a new, empty BoundedVecDeque
with space for at least capacity
elements.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let deque: BoundedVecDeque<i32> = BoundedVecDeque::with_capacity(63, 255); assert!(deque.is_empty()); assert_eq!(deque.max_len(), 255); assert!(deque.capacity() >= 63);
pub fn from_iter<I>(iterable: I, max_len: usize) -> Self where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
Creates a new BoundedVecDeque
from an iterator or iterable.
At most max_len
items are taken from the iterator.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let five_fives = ::std::iter::repeat(5).take(5); let deque: BoundedVecDeque<i32> = BoundedVecDeque::from_iter(five_fives, 7); assert!(deque.iter().eq(&[5, 5, 5, 5, 5])); let mut numbers = 0..; let deque: BoundedVecDeque<i32> = BoundedVecDeque::from_iter(numbers.by_ref(), 7); assert!(deque.iter().eq(&[0, 1, 2, 3, 4, 5, 6])); assert_eq!(numbers.next(), Some(7));
pub fn from_unbounded(vec_deque: VecDeque<T>, max_len: usize) -> Self
[src]
Creates a new BoundedVecDeque
from a VecDeque
.
If vec_deque
contains more than max_len
items, excess items are dropped from the back.
If the capacity is greater than max_len
, it is shrunk to fit.
Examples
use ::std::collections::VecDeque; use ::bounded_vec_deque::BoundedVecDeque; let unbounded = VecDeque::from(vec![42]); let bounded = BoundedVecDeque::from_unbounded(unbounded, 255);
pub fn into_unbounded(self) -> VecDeque<T>
[src]
Converts the BoundedVecDeque
to VecDeque
.
This is a minimal-cost conversion.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let bounded = BoundedVecDeque::from_iter(vec![0, 1, 2, 3], 255); let unbounded = bounded.into_unbounded();
pub fn get_mut(&mut self, index: usize) -> Option<&mut T>
[src]
Returns a mutable reference to an element in the VecDeque
by index.
Returns None
if there is no such element.
The element at index 0
is the front of the queue.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(12); deque.push_back(3); deque.push_back(4); deque.push_back(5); if let Some(elem) = deque.get_mut(1) { *elem = 7; } assert!(deque.iter().eq(&[3, 7, 5]));
pub fn swap(&mut self, i: usize, j: usize)
[src]
Swaps the elements at indices i
and j
.
i
and j
may be equal.
The element at index 0
is the front of the queue.
Panics
Panics if either index is out of bounds.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(12); deque.push_back(3); deque.push_back(4); deque.push_back(5); assert!(deque.iter().eq(&[3, 4, 5])); deque.swap(0, 2); assert!(deque.iter().eq(&[5, 4, 3]));
pub fn reserve(&mut self, additional: usize)
[src]
Reserves capacity for at least additional
more elements to be inserted.
To avoid frequent reallocations, more space than requested may be reserved.
Panics
Panics if the requested new capacity exceeds the maximum length, or if the actual new
capacity overflows usize
.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::from_iter(vec![1], 255); deque.reserve(10); assert!(deque.capacity() >= 11);
pub fn reserve_exact(&mut self, additional: usize)
[src]
Reserves the minimum capacity for exactly additional
more elements to be inserted.
Does nothing if the capacity is already sufficient.
Note that the allocator may give the collection more space than it requests. Therefore
capacity cannot be relied upon to be precisely minimal. Prefer reserve()
if future
insertions are expected.
At the time of writing, this method is equivalent to reserve()
because of
VecDeque
's capacity management. It has been provided anyway for compatibility reasons.
See the relevant section of the type-level documentation for details.
Panics
Panics if the requested new capacity exceeds the maximum length, or if the actual new
capacity overflows usize
.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::from_iter(vec![1], 255); deque.reserve_exact(10); assert!(deque.capacity() >= 11);
pub fn reserve_maximum(&mut self)
[src]
Reserves enough capacity for the collection to be filled to its maximum length.
Does nothing if the capacity is already sufficient.
See the reserve_exact()
documentation for caveats about capacity management.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::from_iter(vec![1], 255); deque.reserve_maximum(); assert!(deque.capacity() >= 255);
pub fn shrink_to_fit(&mut self)
[src]
Reduces the capacity as much as possible.
The capacity is reduced to as close to the length as possible. However, there are
restrictions on how much the capacity can be reduced, and on top of that, the
allocator may not shrink the allocation as much as VecDeque
requests.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::with_capacity(15, 15); deque.push_back(0); deque.push_back(1); deque.push_back(2); deque.push_back(3); assert_eq!(deque.capacity(), 15); deque.shrink_to_fit(); assert!(deque.capacity() >= 4);
pub fn max_len(&self) -> usize
[src]
Returns the maximum number of elements.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let deque: BoundedVecDeque<i32> = BoundedVecDeque::new(255); assert_eq!(deque.max_len(), 255);
ⓘImportant traits for Drain<'a, T>pub fn set_max_len(&mut self, max_len: usize) -> Drain<T>
[src]
Changes the maximum number of elements to max_len
.
If there are more elements than the new maximum, they are removed from the back and yielded by the returned iterator (in front-to-back order).
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque: BoundedVecDeque<i32> = BoundedVecDeque::new(7); deque.extend(vec![0, 1, 2, 3, 4, 5, 6]); assert_eq!(deque.max_len(), 7); assert!(deque.set_max_len(3).eq(vec![3, 4, 5, 6])); assert_eq!(deque.max_len(), 3); assert!(deque.iter().eq(&[0, 1, 2]));
pub fn truncate(&mut self, new_len: usize)
[src]
Decreases the length, dropping excess elements from the back.
If new_len
is greater than the current length, this has no effect.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(7); deque.push_back(5); deque.push_back(10); deque.push_back(15); assert!(deque.iter().eq(&[5, 10, 15])); deque.truncate(1); assert!(deque.iter().eq(&[5]));
ⓘImportant traits for Iter<'a, T>pub fn iter(&self) -> Iter<T>
[src]
Returns a front-to-back iterator of immutable references.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(7); deque.push_back(5); deque.push_back(3); deque.push_back(4); let deque_of_references: Vec<&i32> = deque.iter().collect(); assert_eq!(&deque_of_references[..], &[&5, &3, &4]);
ⓘImportant traits for IterMut<'a, T>pub fn iter_mut(&mut self) -> IterMut<T>
[src]
Returns a front-to-back iterator of mutable references.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(7); deque.push_back(5); deque.push_back(3); deque.push_back(4); for number in deque.iter_mut() { *number -= 2; } let deque_of_references: Vec<&mut i32> = deque.iter_mut().collect(); assert_eq!(&deque_of_references[..], &[&mut 3, &mut 1, &mut 2]);
pub fn as_unbounded(&self) -> &VecDeque<T>
[src]
Returns a reference to the underlying VecDeque
.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let bounded = BoundedVecDeque::from_iter(vec![0, 1, 2, 3], 255); let unbounded_ref = bounded.as_unbounded();
pub fn as_mut_slices(&mut self) -> (&mut [T], &mut [T])
[src]
Returns a pair of slices which contain the contents in order.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(7); deque.push_back(0); deque.push_back(1); deque.push_front(10); deque.push_front(9); deque.as_mut_slices().0[0] = 42; deque.as_mut_slices().1[0] = 24; assert_eq!(deque.as_slices(), (&[42, 10][..], &[24, 1][..]));
pub fn is_full(&self) -> bool
[src]
Returns true
if the BoundedVecDeque
is full (and false otherwise).
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(3); deque.push_back(0); assert!(!deque.is_full()); deque.push_back(1); assert!(!deque.is_full()); deque.push_back(2); assert!(deque.is_full());
ⓘImportant traits for Drain<'a, T>pub fn drain<R>(&mut self, range: R) -> Drain<T> where
R: RangeBounds<usize>,
[src]
R: RangeBounds<usize>,
Creates a draining iterator that removes the specified range 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 (e.g. due to forget()
).
Panics
Panics if the start index is greater than the end index or if the end index is greater than the length of the deque.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::from_iter(vec![0, 1, 2, 3], 7); assert!(deque.drain(2..).eq(vec![2, 3])); assert!(deque.iter().eq(&[0, 1])); // A full range clears all contents deque.drain(..); assert!(deque.is_empty());
pub fn clear(&mut self)
[src]
Removes all values.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(7); deque.push_back(0); assert!(!deque.is_empty()); deque.clear(); assert!(deque.is_empty());
pub fn front_mut(&mut self) -> Option<&mut T>
[src]
Returns a mutable reference to the front element.
Returns None
if the deque is empty.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(7); assert_eq!(deque.front_mut(), None); deque.push_back(0); deque.push_back(1); if let Some(x) = deque.front_mut() { *x = 9; } assert_eq!(deque.front(), Some(&9));
pub fn back_mut(&mut self) -> Option<&mut T>
[src]
Returns a mutable reference to the back element.
Returns None
if the deque is empty.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(7); assert_eq!(deque.back_mut(), None); deque.push_back(0); deque.push_back(1); if let Some(x) = deque.back_mut() { *x = 9; } assert_eq!(deque.back(), Some(&9));
pub fn push_front(&mut self, value: T) -> Option<T>
[src]
Pushes an element onto the front of the deque.
If the deque is full, an element is removed from the back and returned.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(2); assert_eq!(deque.push_front(0), None); assert_eq!(deque.push_front(1), None); assert_eq!(deque.push_front(2), Some(0)); assert_eq!(deque.push_front(3), Some(1)); assert_eq!(deque.front(), Some(&3));
pub fn pop_front(&mut self) -> Option<T>
[src]
Removes and returns the first element.
Returns None
if the deque is empty.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(7); deque.push_back(0); deque.push_back(1); assert_eq!(deque.pop_front(), Some(0)); assert_eq!(deque.pop_front(), Some(1)); assert_eq!(deque.pop_front(), None);
pub fn push_back(&mut self, value: T) -> Option<T>
[src]
Pushes an element onto the back of the deque.
If the deque is full, an element is removed from the front and returned.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(2); assert_eq!(deque.push_back(0), None); assert_eq!(deque.push_back(1), None); assert_eq!(deque.push_back(2), Some(0)); assert_eq!(deque.push_back(3), Some(1)); assert_eq!(deque.back(), Some(&3));
pub fn pop_back(&mut self) -> Option<T>
[src]
Removes and returns the last element.
Returns None
if the deque is empty.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(7); deque.push_back(0); deque.push_back(1); assert_eq!(deque.pop_back(), Some(1)); assert_eq!(deque.pop_back(), Some(0)); assert_eq!(deque.pop_back(), None);
pub fn swap_remove_front(&mut self, index: usize) -> Option<T>
[src]
Removes and returns the element at index
, filling the gap with the element at the front.
This does not preserve ordering, but is O(1)
.
Returns None
if index
is out of bounds.
The element at index 0
is the front of the queue.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(7); assert_eq!(deque.swap_remove_front(0), None); deque.extend(vec![0, 1, 2, 3, 4, 5, 6]); assert_eq!(deque.swap_remove_front(3), Some(3)); assert!(deque.iter().eq(&[1, 2, 0, 4, 5, 6]));
pub fn swap_remove_back(&mut self, index: usize) -> Option<T>
[src]
Removes and returns the element at index
, filling the gap with the element at the back.
This does not preserve ordering, but is O(1)
.
Returns None
if index
is out of bounds.
The element at index 0
is the front of the queue.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(7); assert_eq!(deque.swap_remove_back(0), None); deque.extend(vec![0, 1, 2, 3, 4, 5, 6]); assert_eq!(deque.swap_remove_back(3), Some(3)); assert!(deque.iter().eq(&[0, 1, 2, 6, 4, 5]));
pub fn insert_spill_back(&mut self, index: usize, value: T) -> Option<T>
[src]
Inserts an element at index
in the deque, displacing the back if necessary.
Elements with indices greater than or equal to index
are shifted one place towards the
back to make room. If the deque is full, an element is removed from the back and returned.
The element at index 0
is the front of the queue.
Panics
Panics if index
is greater than the length.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(5); deque.extend(vec!['a', 'b', 'c', 'd']); assert_eq!(deque.insert_spill_back(1, 'e'), None); assert!(deque.iter().eq(&['a', 'e', 'b', 'c', 'd'])); assert_eq!(deque.insert_spill_back(1, 'f'), Some('d')); assert!(deque.iter().eq(&['a', 'f', 'e', 'b', 'c']));
pub fn insert_spill_front(&mut self, index: usize, value: T) -> Option<T>
[src]
Inserts an element at index
in the deque, displacing the front if necessary.
If the deque is full, an element is removed from the front and returned, and elements with
indices less than or equal to index
are shifted one place towards the front to make room.
Otherwise, elements with indices greater than or equal to index
are shifted one place
towards the back to make room.
The element at index 0
is the front of the queue.
Panics
Panics if index
is greater than the length.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(5); deque.extend(vec!['a', 'b', 'c', 'd']); assert_eq!(deque.insert_spill_front(3, 'e'), None); assert!(deque.iter().eq(&['a', 'b', 'c', 'e', 'd'])); assert_eq!(deque.insert_spill_front(3, 'f'), Some('a')); assert!(deque.iter().eq(&['b', 'c', 'e', 'f', 'd']));
pub fn remove(&mut self, index: usize) -> Option<T>
[src]
Removes and returns the element at index
.
Elements with indices greater than index
are shifted towards the front to fill the gap.
Returns None
if index
is out of bounds.
The element at index 0
is the front of the queue.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(7); assert_eq!(deque.remove(0), None); deque.extend(vec![0, 1, 2, 3, 4, 5, 6]); assert_eq!(deque.remove(3), Some(3)); assert!(deque.iter().eq(&[0, 1, 2, 4, 5, 6]));
pub fn split_off(&mut self, at: usize) -> Self
[src]
Splits the deque in two at the given index.
Returns a new BoundedVecDeque
containing elements [at, len)
, leaving self
with
elements [0, at)
. The capacity and maximum length of self
are unchanged, and the new
deque has the same maximum length as self
.
The element at index 0
is the front of the queue.
Panics
Panics if at > len
.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::from_iter(vec![0, 1, 2, 3], 7); let other_deque = deque.split_off(2); assert!(other_deque.iter().eq(&[2, 3])); assert!(deque.iter().eq(&[0, 1]));
ⓘImportant traits for Append<'a, T>pub fn append<'a>(&'a mut self, other: &'a mut Self) -> Append<'a, T>
[src]
Moves all the elements of other
into self
, leaving other
empty.
Elements from other
are pushed onto the back of self
. If the maximum length is
exceeded, excess elements from the front of self
are yielded by the returned iterator.
Panics
Panics if the new number of elements in self overflows a usize
.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::from_iter(vec![0, 1, 2, 3], 7); let mut other_deque = BoundedVecDeque::from_iter(vec![4, 5, 6, 7, 8], 7); assert!(deque.append(&mut other_deque).eq(vec![0, 1])); assert!(deque.iter().eq(&[2, 3, 4, 5, 6, 7, 8])); assert!(other_deque.is_empty());
pub fn retain<F>(&mut self, predicate: F) where
F: FnMut(&T) -> bool,
[src]
F: FnMut(&T) -> bool,
Retains only the elements specified by the predicate.
predicate
is called for each element; each element for which it returns false
is
removed. This method operates in place and preserves the order of the retained elements.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::from_iter(1..5, 7); deque.retain(|&x| x % 2 == 0); assert!(deque.iter().eq(&[2, 4]));
pub fn resize(&mut self, new_len: usize, value: T) where
T: Clone,
[src]
T: Clone,
Modifies the deque in-place so that its length is equal to new_len
.
This is done either by removing excess elements from the back or by pushing clones of
value
to the back.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::from_iter(vec![5, 10, 15], 7); deque.resize(2, 0); assert!(deque.iter().eq(&[5, 10])); deque.resize(5, 20); assert!(deque.iter().eq(&[5, 10, 20, 20, 20]));
pub fn resize_with<F>(&mut self, new_len: usize, producer: F) where
F: FnMut() -> T,
[src]
F: FnMut() -> T,
Modifies the deque in-place so that its length is equal to new_len
.
This is done either by removing excess elements from the back or by pushing elements
produced by calling producer
to the back.
Availability
This method requires the resize_with
feature, which requires Rust 1.33.
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::from_iter(vec![5, 10, 15], 7); deque.resize_with(5, Default::default); assert!(deque.iter().eq(&[5, 10, 15, 0, 0])); deque.resize_with(2, || unreachable!()); assert!(deque.iter().eq(&[5, 10])); let mut state = 100; deque.resize_with(5, || { state += 1; state }); assert!(deque.iter().eq(&[5, 10, 101, 102, 103]));
Methods from Deref<Target = VecDeque<T>>
pub fn get(&self, index: usize) -> Option<&T>
1.0.0[src]
Retrieves an element in the VecDeque
by index.
Element at index 0 is the front of the queue.
Examples
use std::collections::VecDeque; let mut buf = VecDeque::new(); buf.push_back(3); buf.push_back(4); buf.push_back(5); assert_eq!(buf.get(1), Some(&4));
pub fn capacity(&self) -> usize
1.0.0[src]
Returns the number of elements the VecDeque
can hold without
reallocating.
Examples
use std::collections::VecDeque; let buf: VecDeque<i32> = VecDeque::with_capacity(10); assert!(buf.capacity() >= 10);
pub fn iter(&self) -> Iter<T>
1.0.0[src]
Returns a front-to-back iterator.
Examples
use std::collections::VecDeque; let mut buf = VecDeque::new(); buf.push_back(5); buf.push_back(3); buf.push_back(4); let b: &[_] = &[&5, &3, &4]; let c: Vec<&i32> = buf.iter().collect(); assert_eq!(&c[..], b);
pub fn as_slices(&self) -> (&[T], &[T])
1.5.0[src]
Returns a pair of slices which contain, in order, the contents of the
VecDeque
.
Examples
use std::collections::VecDeque; let mut vector = VecDeque::new(); vector.push_back(0); vector.push_back(1); vector.push_back(2); assert_eq!(vector.as_slices(), (&[0, 1, 2][..], &[][..])); vector.push_front(10); vector.push_front(9); assert_eq!(vector.as_slices(), (&[9, 10][..], &[0, 1, 2][..]));
pub fn len(&self) -> usize
1.0.0[src]
Returns the number of elements in the VecDeque
.
Examples
use std::collections::VecDeque; let mut v = VecDeque::new(); assert_eq!(v.len(), 0); v.push_back(1); assert_eq!(v.len(), 1);
pub fn is_empty(&self) -> bool
1.0.0[src]
Returns true
if the VecDeque
is empty.
Examples
use std::collections::VecDeque; let mut v = VecDeque::new(); assert!(v.is_empty()); v.push_front(1); assert!(!v.is_empty());
pub fn contains(&self, x: &T) -> bool where
T: PartialEq<T>,
1.12.0[src]
T: PartialEq<T>,
Returns true
if the VecDeque
contains an element equal to the
given value.
Examples
use std::collections::VecDeque; let mut vector: VecDeque<u32> = VecDeque::new(); vector.push_back(0); vector.push_back(1); assert_eq!(vector.contains(&1), true); assert_eq!(vector.contains(&10), false);
pub fn front(&self) -> Option<&T>
1.0.0[src]
Provides a reference to the front element, or None
if the VecDeque
is
empty.
Examples
use std::collections::VecDeque; let mut d = VecDeque::new(); assert_eq!(d.front(), None); d.push_back(1); d.push_back(2); assert_eq!(d.front(), Some(&1));
pub fn back(&self) -> Option<&T>
1.0.0[src]
Provides a reference to the back element, or None
if the VecDeque
is
empty.
Examples
use std::collections::VecDeque; let mut d = VecDeque::new(); assert_eq!(d.back(), None); d.push_back(1); d.push_back(2); assert_eq!(d.back(), Some(&2));
Trait Implementations
impl<T> AsRef<VecDeque<T>> for BoundedVecDeque<T>
[src]
impl<T> IntoIterator for BoundedVecDeque<T>
[src]
type Item = T
The type of the elements being iterated over.
type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T> IntoIterator for &'a BoundedVecDeque<T>
[src]
type Item = &'a T
The type of the elements being iterated over.
type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, T> IntoIterator for &'a mut BoundedVecDeque<T>
[src]
type Item = &'a mut T
The type of the elements being iterated over.
type IntoIter = IterMut<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<T> Extend<T> for BoundedVecDeque<T>
[src]
fn extend<I>(&mut self, iter: I) where
I: IntoIterator<Item = T>,
[src]
I: IntoIterator<Item = T>,
impl<T: Clone> Clone for BoundedVecDeque<T>
[src]
fn clone(&self) -> Self
[src]
fn clone_from(&mut self, other: &Self)
[src]
Mutates self
into a clone of other
(like *self = other.clone()
).
self
is cleared, and the elements of other
are cloned and added. The maximum length is
set to the same as other
's.
This method reuses self
's allocation, but due to API limitations, the allocation cannot
be shrunk to fit the maximum length. Because of this, if self
's capacity is more than the
new maximum length, it is shrunk to fit other
's length.
impl<T> Deref for BoundedVecDeque<T>
[src]
type Target = VecDeque<T>
The resulting type after dereferencing.
fn deref(&self) -> &Self::Target
[src]
impl<T: Hash> Hash for BoundedVecDeque<T>
[src]
fn hash<H>(&self, hasher: &mut H) where
H: Hasher,
[src]
H: Hasher,
Feeds self
into hasher
.
Only the values contained in self
are hashed; the length bound is ignored.
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
Feeds a slice of this type into the given [Hasher
]. Read more
impl<T> Index<usize> for BoundedVecDeque<T>
[src]
type Output = T
The returned type after indexing.
fn index(&self, index: usize) -> &T
[src]
Returns a reference to an element in the VecDeque
by index.
The element at index 0
is the front of the queue.
Panics
Panics if there is no such element (i.e. index >= len
).
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(7); deque.push_back(3); deque.push_back(4); deque.push_back(5); let value = &deque[1]; assert_eq!(value, &4);
impl<T> IndexMut<usize> for BoundedVecDeque<T>
[src]
fn index_mut(&mut self, index: usize) -> &mut T
[src]
Returns a mutable reference to an element in the VecDeque
by index.
The element at index 0
is the front of the queue.
Panics
Panics if there is no such element (i.e. index >= len
).
Examples
use ::bounded_vec_deque::BoundedVecDeque; let mut deque = BoundedVecDeque::new(12); deque.push_back(3); deque.push_back(4); deque.push_back(5); deque[1] = 7; assert_eq!(deque[1], 7);
impl<T: Debug> Debug for BoundedVecDeque<T>
[src]
Auto Trait Implementations
impl<T> Send for BoundedVecDeque<T> where
T: Send,
T: Send,
impl<T> Unpin for BoundedVecDeque<T> where
T: Unpin,
T: Unpin,
impl<T> Sync for BoundedVecDeque<T> where
T: Sync,
T: Sync,
impl<T> UnwindSafe for BoundedVecDeque<T> where
T: UnwindSafe,
T: UnwindSafe,
impl<T> RefUnwindSafe for BoundedVecDeque<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
type Item = <I as Iterator>::Item
The type of the elements being iterated over.
type IntoIter = I
Which kind of iterator are we turning this into?
fn into_iter(self) -> I
[src]
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &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>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,