[−][src]Struct const_arrayvec::ArrayVec
A vector type backed by a fixed-length array.
Methods
impl<T, const N: usize> ArrayVec<T, { N }>
[src]
pub fn new() -> ArrayVec<T, { N }>
[src]
Create a new, empty ArrayVec
.
pub const fn len(&self) -> usize
[src]
pub const fn is_empty(&self) -> bool
[src]
pub const fn capacity(&self) -> usize
[src]
pub const fn remaining_capacity(&self) -> usize
[src]
pub const fn is_full(&self) -> bool
[src]
pub fn as_ptr(&self) -> *const T
[src]
pub fn as_mut_ptr(&mut self) -> *mut T
[src]
pub fn push(&mut self, item: T)
[src]
Add an item to the end of the vector.
Examples
use const_arrayvec::ArrayVec; let mut vector: ArrayVec<u32, 5> = ArrayVec::new(); assert!(vector.is_empty()); vector.push(42); assert_eq!(vector.len(), 1); assert_eq!(vector[0], 42);
pub fn try_push(&mut self, item: T) -> Result<(), CapacityError<T>>
[src]
Try to add an item to the end of the vector, returning the original item if there wasn't enough room.
Examples
use const_arrayvec::{ArrayVec, CapacityError}; let mut vector: ArrayVec<u32, 2> = ArrayVec::new(); assert!(vector.try_push(1).is_ok()); assert!(vector.try_push(2).is_ok()); assert!(vector.is_full()); assert_eq!(vector.try_push(42), Err(CapacityError(42)));
pub unsafe fn push_unchecked(&mut self, item: T)
[src]
Add an item to the end of the array without checking the capacity.
Safety
It is up to the caller to ensure the vector's capacity is suitably large.
This method uses debug assertions to detect overflows in debug builds.
pub unsafe fn set_len(&mut self, new_length: usize)
[src]
Set the vector's length without dropping or moving out elements.
Safety
This method is unsafe
because it changes the number of "valid"
elements the vector thinks it contains, without adding or removing any
elements. Use with care.
pub fn pop(&mut self) -> Option<T>
[src]
Remove an item from the end of the vector.
Examples
let mut vector: ArrayVec<u32, 5> = ArrayVec::new(); vector.push(12); vector.push(34); assert_eq!(vector.len(), 2); let got = vector.pop(); assert_eq!(got, Some(34)); assert_eq!(vector.len(), 1);
pub fn truncate(&mut self, new_length: usize)
[src]
Shorten the vector, keeping the first new_length
elements and dropping
the rest.
pub fn clear(&mut self)
[src]
Remove all items from the vector.
pub fn insert(&mut self, index: usize, item: T)
[src]
Insert an item.
Panics
The vector must have enough space for the item (see
ArrayVec::remaining_capacity()
).
pub fn try_insert(
&mut self,
index: usize,
item: T
) -> Result<(), CapacityError<T>>
[src]
&mut self,
index: usize,
item: T
) -> Result<(), CapacityError<T>>
Try to insert an item into the vector.
Examples
The "happy path" works just as expected:
use const_arrayvec::ArrayVec; let mut vector: ArrayVec<u32, 5> = ArrayVec::new(); vector.push(12); vector.push(34); vector.try_insert(1, 56).unwrap(); assert_eq!(vector.as_slice(), &[12, 56, 34]);
Trying to insert an item when the ArrayVec
is full will fail,
returning the original item.
use const_arrayvec::{ArrayVec, CapacityError}; let mut vector = ArrayVec::from([1, 2, 3]); println!("{}, {}", vector.len(), vector.capacity()); println!("{:?}", vector); assert!(vector.is_full()); let got = vector.try_insert(1, 7); assert_eq!(got, Err(CapacityError(7)));
pub fn as_slice(&self) -> &[T]
[src]
pub fn as_slice_mut(&mut self) -> &mut [T]
[src]
pub fn try_extend_from_slice(
&mut self,
other: &[T]
) -> Result<(), CapacityError<()>> where
T: Copy,
[src]
&mut self,
other: &[T]
) -> Result<(), CapacityError<()>> where
T: Copy,
ⓘImportant traits for Drain<'a, T, { N }>pub fn drain(&mut self, range: Range<usize>) -> Drain<T, { N }>
[src]
Trait Implementations
impl<T, const N: usize> From<[T; N]> for ArrayVec<T, { N }>
[src]
impl<T: Debug, const N: usize> Debug for ArrayVec<T, { N }>
[src]
impl<T: PartialEq, const N: usize, const M: usize> PartialEq<ArrayVec<T, M>> for ArrayVec<T, { N }>
[src]
fn eq(&self, other: &ArrayVec<T, { M }>) -> bool
[src]
#[must_use]
fn ne(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T: PartialEq, const N: usize> PartialEq<[T]> for ArrayVec<T, { N }>
[src]
impl<T: Eq, const N: usize> Eq for ArrayVec<T, { N }>
[src]
impl<T: Ord, const N: usize> Ord for ArrayVec<T, { N }>
[src]
fn cmp(&self, other: &Self) -> Ordering
[src]
fn max(self, other: Self) -> Self
1.21.0[src]
fn min(self, other: Self) -> Self
1.21.0[src]
fn clamp(self, min: Self, max: Self) -> Self
[src]
impl<T: PartialOrd, const N: usize> PartialOrd<ArrayVec<T, N>> for ArrayVec<T, { N }>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]
fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]
fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T, const N: usize> Deref for ArrayVec<T, { N }>
[src]
impl<T, const N: usize> DerefMut for ArrayVec<T, { N }>
[src]
impl<T, const N: usize> Drop for ArrayVec<T, { N }>
[src]
fn drop(&mut self)
[src]
Makes sure all items are cleaned up once you're done with the
ArrayVec
.
Examples
use core::{mem, sync::atomic::{AtomicUsize, Ordering}}; use const_arrayvec::ArrayVec; // create a dummy type which increments a number when dropped struct OnDropped<'a>(&'a AtomicUsize); impl<'a> Drop for OnDropped<'a> { fn drop(&mut self) { self.0.fetch_add(1, Ordering::Relaxed); } } // create our vector let mut vector: ArrayVec<OnDropped<'_>, 5> = ArrayVec::new(); // then set up our counter let counter = AtomicUsize::new(0); // and add a couple `OnDropped`'s to the vector vector.push(OnDropped(&counter)); vector.push(OnDropped(&counter)); vector.push(OnDropped(&counter)); // the vector is still live so our counter shouldn't have changed assert_eq!(counter.load(Ordering::Relaxed), 0); // explicitly drop the vector mem::drop(vector); // and the counter should have updated assert_eq!(counter.load(Ordering::Relaxed), 3);
impl<Ix, T, const N: usize> Index<Ix> for ArrayVec<T, { N }> where
[T]: Index<Ix>,
[src]
[T]: Index<Ix>,
type Output = <[T] as Index<Ix>>::Output
The returned type after indexing.
fn index(&self, ix: Ix) -> &Self::Output
[src]
impl<Ix, T, const N: usize> IndexMut<Ix> for ArrayVec<T, { N }> where
[T]: IndexMut<Ix>,
[src]
[T]: IndexMut<Ix>,
impl<T: Hash, const N: usize> Hash for ArrayVec<T, { N }>
[src]
fn hash<H: Hasher>(&self, hasher: &mut H)
[src]
fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl<T, const N: usize> AsRef<[T]> for ArrayVec<T, { N }>
[src]
impl<T, const N: usize> AsMut<[T]> for ArrayVec<T, { N }>
[src]
impl<T: Clone, const N: usize> Clone for ArrayVec<T, { N }>
[src]
fn clone(&self) -> ArrayVec<T, { N }>
[src]
fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl<T, const N: usize> Default for ArrayVec<T, { N }>
[src]
Auto Trait Implementations
impl<const N: usize, T> Unpin for ArrayVec<T, N> where
T: Unpin,
T: Unpin,
impl<const N: usize, T> Send for ArrayVec<T, N> where
T: Send,
T: Send,
impl<const N: usize, T> Sync for ArrayVec<T, N> where
T: Sync,
T: Sync,
Blanket Implementations
impl<T> From<T> for T
[src]
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> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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> 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> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,