Struct trait_based_collection::stack::ArrayStack
source · [−]pub struct ArrayStack<T> {
pub mode: ExpansionMode,
/* private fields */
}
Expand description
A fixed-size stack capable of expanding when needed. It is implemented using Vec
,
so the elements are stored contiguously in memory. The main difference between this and a
Stack
is that this one does not use nodes.
Depending on the expansion mode, once the capacity is reached, the deque will behave differently
depending on the mode. For more information, see the ExpansionMode
documentation.
Examples
use trait_based_collection::{prelude::*, ArrayStack};
let mut stack = ArrayStack::with_mode(2, ExpansionMode::Ignore);
stack.add(1);
stack.add(2);
stack.add(3);
assert_eq!(stack.len(), 2);
assert_eq!(stack.remove(), Some(2));
assert_eq!(stack.remove(), Some(1));
assert_eq!(stack.remove(), None);
Fields
mode: ExpansionMode
The current mode of expansion of the deque that determinate the behaviour the collection is
full. See ExpansionMode
for more information.
Trait Implementations
sourceimpl<'a, T: 'a> Collection<'a, T> for ArrayStack<T>
impl<'a, T: 'a> Collection<'a, T> for ArrayStack<T>
sourcefn new_default() -> Self
fn new_default() -> Self
Creates a new
Collection
with a default capacity. Read moresourcefn with_capacity(capacity: usize) -> Self
fn with_capacity(capacity: usize) -> Self
Creates a new
Collection
with a specific capacity. Read moresourcefn with_approximate_capacity(approx_capacity: usize) -> Self
fn with_approximate_capacity(approx_capacity: usize) -> Self
Creates a new
Collection
with a capacity that is at least the specified capacity. Read moresourcefn add(&mut self, value: T)
fn add(&mut self, value: T)
Adds an item to the
Collection
. Read moresourcefn remove(&mut self) -> Option<T>
fn remove(&mut self) -> Option<T>
Removes an item from the
Collection
. Read moresourcefn clear(&mut self)
fn clear(&mut self)
Clears all items from the
Collection
while keeping the capacity. Read moresourcefn peek(&'a self) -> Option<Self::ItemRef>
fn peek(&'a self) -> Option<Self::ItemRef>
Returns an immutable reference of the item that will be removed next. Read more
sourcefn peek_mut(&'a mut self) -> Option<Self::ItemMut>
fn peek_mut(&'a mut self) -> Option<Self::ItemMut>
Returns a mutable reference of the item that will be removed next. Read more
sourcefn len(&self) -> usize
fn len(&self) -> usize
Returns the number of items in the
Collection
. Read moresourcefn get(&'a self, index: usize) -> Option<Self::ItemRef>
fn get(&'a self, index: usize) -> Option<Self::ItemRef>
Returns a immutable reference to the n-th item in the
Collection
. Read moresourcefn get_mut(&'a mut self, index: usize) -> Option<Self::ItemMut>
fn get_mut(&'a mut self, index: usize) -> Option<Self::ItemMut>
Returns a mutable reference to the n-th item in the
Collection
. Read moresourcefn is_empty(&self) -> bool
fn is_empty(&self) -> bool
Checks if the
Collection
is empty. Read moresourceimpl<T: Debug> Debug for ArrayStack<T>
impl<T: Debug> Debug for ArrayStack<T>
sourceimpl<T> Default for ArrayStack<T>
impl<T> Default for ArrayStack<T>
sourceimpl<T> Display for ArrayStack<T>where
T: Display,
impl<T> Display for ArrayStack<T>where
T: Display,
sourceimpl<T> Drop for ArrayStack<T>
impl<T> Drop for ArrayStack<T>
sourceimpl<T> Extend<T> for ArrayStack<T>
impl<T> Extend<T> for ArrayStack<T>
sourcefn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
🔬This is a nightly-only experimental API. (
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
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
sourceimpl<'a, T: 'a> FixedSizeCollection<'a, T> for ArrayStack<T>
impl<'a, T: 'a> FixedSizeCollection<'a, T> for ArrayStack<T>
sourcefn with_mode(capacity: usize, mode: ExpansionMode) -> Self
fn with_mode(capacity: usize, mode: ExpansionMode) -> Self
sourcefn capacity(&self) -> usize
fn capacity(&self) -> usize
Returns the maximum amount of items that the collection can hold without expanding. Read more
sourcefn expand(&mut self, extra_size: usize)
fn expand(&mut self, extra_size: usize)
Expands the capacity of the collection by at least the specified amount. This amount or more
will be dded to the capacity. Read more
sourcefn mode(&self) -> &ExpansionMode
fn mode(&self) -> &ExpansionMode
Returns the
ExpansionMode
of the collection . This is used to determine how the
collection will behave when it is full. Read moresourcefn is_full(&self) -> bool
fn is_full(&self) -> bool
Checks if the number of items in the
FixedSizeCollection
is equal to the capacity. Read moresourceimpl<T> FromIterator<T> for ArrayStack<T>
impl<T> FromIterator<T> for ArrayStack<T>
sourcefn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Self
Creates a value from an iterator. Read more
sourceimpl<T> Index<usize> for ArrayStack<T>
impl<T> Index<usize> for ArrayStack<T>
sourceimpl<T> IndexMut<usize> for ArrayStack<T>
impl<T> IndexMut<usize> for ArrayStack<T>
sourceimpl<'a, T> IntoIterator for &'a ArrayStack<T>
impl<'a, T> IntoIterator for &'a ArrayStack<T>
sourceimpl<'a, T> IntoIterator for &'a mut ArrayStack<T>
impl<'a, T> IntoIterator for &'a mut ArrayStack<T>
sourceimpl<T> IntoIterator for ArrayStack<T>
impl<T> IntoIterator for ArrayStack<T>
sourceimpl<'a, T: 'a> Iterators<'a, T> for ArrayStack<T>
impl<'a, T: 'a> Iterators<'a, T> for ArrayStack<T>
type ItemRef = &'a T
type ItemRef = &'a T
The type of reference the immutable iterator (
Iter
) iterates over the items in the
Collection
. The reference is only valid for the duration of the iteration. Read moretype ItemMut = &'a mut T
type ItemMut = &'a mut T
The type of mutable reference the mutable iterator (
IterMut
) iterates over the items in
the Collection
. The reference is only valid for the duration of the iteration. Read moresourcefn iter(&'a self) -> Self::Iter
fn iter(&'a self) -> Self::Iter
Creates an immutable iterator over the items in the
Collection
without consuming them. Read moresourcefn iter_mut(&'a mut self) -> Self::IterMut
fn iter_mut(&'a mut self) -> Self::IterMut
Creates a mutable iterator over the items in the
Collection
without consuming them. Read moreAuto Trait Implementations
impl<T> RefUnwindSafe for ArrayStack<T>where
T: RefUnwindSafe,
impl<T> Send for ArrayStack<T>where
T: Send,
impl<T> Sync for ArrayStack<T>where
T: Sync,
impl<T> Unpin for ArrayStack<T>where
T: Unpin,
impl<T> UnwindSafe for ArrayStack<T>where
T: UnwindSafe,
Blanket Implementations
sourceimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more