[][src]Struct coca::vec::Vec

pub struct Vec<Element, Buf, Idx = usize> where
    Buf: ContiguousStorage<Element>,
    Idx: Capacity
{ /* fields omitted */ }

A contiguous growable array type with constant capacity.

Generic over the storage buffer type Buf and the index type Idx.

See the module-level documentation for more.

Implementations

impl<E, B, I> Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity
[src]

pub fn into_raw_parts(self) -> (B, I)[src]

Decomposes a Vec<E, B, I> into its raw parts.

Returns the raw storage type and the length of the vector in elements. These are the same arguments in the same order as the arguments to from_raw_parts.

Examples

let mut backing_region = [core::mem::MaybeUninit::<u32>::uninit(); 5];
let mut vec = coca::SliceVec::<u32>::from(&mut backing_region[..]);
vec.extend(&[1, 2, 3]);

let (slice, len) = vec.into_raw_parts();
unsafe {
    assert_eq!(slice[0].assume_init(), 1);
    assert_eq!(slice[1].assume_init(), 2);
    assert_eq!(slice[2].assume_init(), 3);
    // other elements are uninitialized
}

pub unsafe fn from_raw_parts(buf: B, length: I) -> Self[src]

Creates a Vec<E, B, I> directly from its raw parts.

Safety

Callers must ensure that values stored in buf at all positions less than length are initialized, and that length is less than or equal to buf.capacity().

let mut backing_region = [core::mem::MaybeUninit::<u32>::uninit(); 5];
let mut vec = coca::SliceVec::<u32>::from(&mut backing_region[..]);
vec.extend(&[1, 2, 3]);

let (buf, length) = vec.into_raw_parts();
let vec = unsafe { coca::SliceVec::<u32>::from_raw_parts(buf, length) };
assert_eq!(vec.as_slice(), &[1, 2, 3]);

pub fn capacity(&self) -> usize[src]

Returns the number of elements the vector can hold.

pub fn len(&self) -> usize[src]

Returns the number of elements in the vector, also referred to as its 'length'.

pub fn is_empty(&self) -> bool[src]

Returns true if the vector contains no elements.

pub fn is_full(&self) -> bool[src]

Returns true if the vector contains the maximum number of elements.

pub fn pop(&mut self) -> Option<E>[src]

Removes the last element from the vector and returns it, or None if it is empty.

Examples

let mut backing_region = [core::mem::MaybeUninit::<u32>::uninit(); 3];
let mut vec = coca::SliceVec::<u32>::from(&mut backing_region[..]);
vec.push(1); vec.push(2); vec.push(3);
assert_eq!(vec.pop(), Some(3));
assert_eq!(vec, &[1, 2][..]);

pub fn as_slice(&self) -> &[E][src]

Extracts a slice containing the entire vector.

Equivalent to &s[..].

pub fn as_mut_slice(&mut self) -> &mut [E][src]

Extracts a mutable slice of the entire vector.

Equivalent to &mut s[..].

pub fn get(&self, index: I) -> Option<&E>[src]

Returns a reference to the element at the specified index, or None if the index is out of bounds.

Examples

let mut backing_region = [core::mem::MaybeUninit::<u32>::uninit(); 3];
let mut vec = coca::SliceVec::<u32>::from(&mut backing_region[..]);
vec.push(1); vec.push(2); vec.push(3);
assert_eq!(vec.get(1), Some(&2));
assert_eq!(vec.get(3), None);

pub fn get_mut(&mut self, index: I) -> Option<&mut E>[src]

Returns a mutable reference to the element at the specified index, or None if the index is out of bounds.

pub fn try_push(&mut self, value: E) -> Result<(), E>[src]

Appends an element to the back of the vector, returning Err(value) if it is already at capacity.

Examples

let mut backing_region = [core::mem::MaybeUninit::<u32>::uninit(); 3];
let mut vec = coca::SliceVec::<u32>::from(&mut backing_region[..]);
assert!(vec.try_push(1).is_ok());
assert!(vec.try_push(2).is_ok());
assert!(vec.try_push(3).is_ok());
assert_eq!(vec.try_push(4), Err(4));

pub fn push(&mut self, value: E)[src]

Appends an element to the back of the vector.

Panics

Panics if the vector is already at capacity. See try_push for a checked version that never panics.

pub fn truncate(&mut self, len: I)[src]

Shortens the vector, keeping the first len elements and dropping the rest.

If len is greater than the vector's current length, this has no effect.

Examples

let mut backing_region = [core::mem::MaybeUninit::<u32>::uninit(); 4];
let mut vec = coca::SliceVec::<u32>::from(&mut backing_region[..]);
vec.push(1); vec.push(2); vec.push(3); vec.push(4);

vec.truncate(6);
assert_eq!(vec, &[1, 2, 3, 4][..]);

vec.truncate(2);
assert_eq!(vec, &[1, 2][..]);

pub fn clear(&mut self)[src]

Clears the vector, dropping all values.

Equivalent to s.truncate(0).

pub fn swap(&mut self, fst: I, snd: I)[src]

Swaps two elements in the vector.

Panics

Pancis if either argument is out of bounds.

Examples

let mut backing_region = [core::mem::MaybeUninit::<u32>::uninit(); 4];
let mut vec = coca::SliceVec::<u32>::from(&mut backing_region[..]);
vec.push(1); vec.push(2); vec.push(3); vec.push(4);

vec.swap(0, 2);
assert_eq!(vec, &[3, 2, 1, 4][..]);

pub fn swap_remove(&mut self, index: I) -> E[src]

Removes an element from the vector and returns it.

The removed element is replaced by the last element of the vector. This does not preserve ordering, but it is O(1).

Panics

Panics if index is out of bounds.

Examples

let mut backing_region = [core::mem::MaybeUninit::<u32>::uninit(); 4];
let mut vec = coca::SliceVec::<u32>::from(&mut backing_region[..]);
vec.push(1); vec.push(2); vec.push(3); vec.push(4);

vec.swap_remove(1);
assert_eq!(vec, &[1, 4, 3][..]);

pub fn insert(&mut self, index: I, element: E)[src]

Inserts an element at position index within the vector, shifting all elements after it to the right.

Panics

Panics if the vector is already full, or if index is out of bounds. See try_insert for a checked version.

pub fn try_insert(&mut self, index: I, element: E) -> Result<(), E>[src]

Inserts an element at position index within the vector, shifting all elements after it to the right.

Returns back Err(element) if the vector is already at capacity.

Panics

Panics if index is out of bounds.

Examples

let mut backing_region = [core::mem::MaybeUninit::<u32>::uninit(); 4];
let mut vec = coca::SliceVec::<u32>::from(&mut backing_region[..]);
vec.push(1); vec.push(2); vec.push(3);

assert!(vec.try_insert(3, 4).is_ok());
assert!(vec.try_insert(4, 5).is_err());
assert_eq!(vec, &[1, 2, 3, 4][..]);

pub fn replace(&mut self, index: I, element: E) -> E[src]

Places an element at position index within the vector, returning the element previously stored there.

Panics

Panics if index is out of bounds.

Examples

let mut backing_region = [core::mem::MaybeUninit::<u32>::uninit(); 4];
let mut vec = coca::SliceVec::<u32>::from(&mut backing_region[..]);
vec.push(1); vec.push(2); vec.push(3);

assert_eq!(vec.replace(1, 4), 2);
assert_eq!(vec, &[1, 4, 3][..]);

pub fn remove(&mut self, index: I) -> E[src]

Removes and returns the element at position index within the vector, shifting all elements after it to the left.

Panics

Panics if index is out of bounds.

Examples

let mut backing_region = [core::mem::MaybeUninit::<u32>::uninit(); 4];
let mut vec = coca::SliceVec::<u32>::from(&mut backing_region[..]);
vec.push(1); vec.push(2); vec.push(3);
vec.remove(0);

assert_eq!(vec, &[2, 3][..]);

pub fn retain<F>(&mut self, f: F) where
    F: FnMut(&E) -> bool, 
[src]

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, visiting each element exactly once in the original order, and preserves the order of the retained elements.

Examples

let mut backing_region = [core::mem::MaybeUninit::<u32>::uninit(); 4];
let mut vec = coca::SliceVec::<u32>::from(&mut backing_region[..]);
vec.push(1); vec.push(2); vec.push(3); vec.push(4);
vec.retain(|&x| x % 2 == 0);

assert_eq!(vec, &[2, 4][..]);

The exact order may be useful for tracking external state, like an index.

let mut backing_region = [core::mem::MaybeUninit::<u32>::uninit(); 4];
let mut vec = coca::SliceVec::<u32>::from(&mut backing_region[..]);
vec.push(1); vec.push(2); vec.push(3); vec.push(4);
let keep = [false, true, true, false];
let mut i = 0;
vec.retain(|_| (keep[i], i += 1).0);

assert_eq!(vec, &[2, 3][..]);

pub fn drain<R: RangeBounds<I>>(&mut self, range: R) -> Drain<'_, E, B, I>

Notable traits for Drain<'p, E, B, I>

impl<'p, E, B, I> Iterator for Drain<'p, E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity
type Item = E;
[src]

Creates a draining iterator that removes the specified range in the vector and yields the removed items.

When the iterator is dropped, all elements in the range are removed from the vector, even if the iterator was not fully consumed. If the iterator is not dropped (with core::mem::forget for example), it is unspecified how many elements are removed.

Panics

Panics if the starting point is greater than the end point or if the end point is greater than the length of the vector.

Examples

let mut backing_region = [core::mem::MaybeUninit::<u32>::uninit(); 5];
let mut vec = coca::SliceVec::<u32>::from(&mut backing_region[..]);
vec.push(1); vec.push(2); vec.push(3); vec.push(4); vec.push(5);
let mut iter = vec.drain(1..3);
assert_eq!(iter.next(), Some(2));
assert_eq!(iter.next(), Some(3));
assert_eq!(iter.next(), None);
drop(iter);
assert_eq!(vec, &[1, 4, 5][..]);

impl<E, I> Vec<E, Box<[MaybeUninit<E>], Global>, I> where
    E: Copy,
    I: Capacity
[src]

pub fn with_capacity(capacity: I) -> Self[src]

This is supported on crate feature alloc only.

Constructs a new, empty AllocVec<E, I> with the specified capacity.

Panics

Panics if the specified capacity cannot be represented by a usize.

impl<E, I, const C: usize> Vec<E, [MaybeUninit<E>; C], I> where
    I: Capacity
[src]

pub fn new() -> Self[src]

This is supported on crate feature nightly only.

Constructs a new, empty Vec backed by an inline array.

Panics

Panics if C cannot be represented as a value of type I.

Examples

let vec = coca::ArrayVec::<u32, 6>::new();
assert_eq!(vec.capacity(), 6);
assert_eq!(vec.len(), 0);

Trait Implementations

impl<E, B, I> AsMut<[E]> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity
[src]

impl<E, B, I> AsRef<[E]> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity
[src]

impl<E, I, const C: usize> Clone for Vec<E, [MaybeUninit<E>; C], I> where
    E: Clone,
    I: Capacity
[src]

This is supported on crate feature nightly only.

impl<E, B, I> Debug for Vec<E, B, I> where
    E: Debug,
    B: ContiguousStorage<E>,
    I: Capacity
[src]

impl<E, I, const C: usize> Default for Vec<E, [MaybeUninit<E>; C], I> where
    I: Capacity
[src]

This is supported on crate feature nightly only.

impl<E, B, I> Deref for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity
[src]

type Target = [E]

The resulting type after dereferencing.

impl<E, B, I> DerefMut for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity
[src]

impl<E, B, I> Drop for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity
[src]

impl<E, B, I> Eq for Vec<E, B, I> where
    E: Eq,
    B: ContiguousStorage<E>,
    I: Capacity
[src]

impl<'a, E, B, Idx> Extend<&'a E> for Vec<E, B, Idx> where
    E: 'a + Clone,
    B: ContiguousStorage<E>,
    Idx: Capacity
[src]

impl<E, B, Idx> Extend<E> for Vec<E, B, Idx> where
    B: ContiguousStorage<E>,
    Idx: Capacity
[src]

impl<E, I, const C: usize> From<&'_ [E]> for Vec<E, [MaybeUninit<E>; C], I> where
    E: Clone,
    I: Capacity
[src]

This is supported on crate feature nightly only.

impl<E, I, const C: usize> From<&'_ mut [E]> for Vec<E, [MaybeUninit<E>; C], I> where
    E: Clone,
    I: Capacity
[src]

This is supported on crate feature nightly only.

impl<E, B, I> From<B> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity
[src]

pub fn from(buf: B) -> Self[src]

Converts a contiguous block of memory into an empty vector.

Panics

This may panic if the index type I cannot represent buf.capacity().

impl<E, B, I> From<Vec<E, B, I>> for BinaryHeap<E, B, I> where
    E: Ord,
    B: ContiguousStorage<E>,
    I: Capacity
[src]

pub fn from(vec: Vec<E, B, I>) -> Self[src]

Converts a Vec into a binary heap.

This conversion happens in-place, and has O(n) time complexity.

impl<E, B: ContiguousStorage<E>, I: Capacity> From<Vec<E, B, I>> for Deque<E, B, I>[src]

impl<E, I, const N: usize> FromIterator<E> for Vec<E, [MaybeUninit<E>; N], I> where
    I: Capacity
[src]

This is supported on crate feature nightly only.

pub fn from_iter<It: IntoIterator<Item = E>>(iter: It) -> Self[src]

Creates a vector backed by an inline array from an iterator.

Panics

Panics if the iterator yields more than N elements.

impl<E, B, I> Hash for Vec<E, B, I> where
    E: Hash,
    B: ContiguousStorage<E>,
    I: Capacity
[src]

impl<E, B, I> Index<I> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity
[src]

type Output = E

The returned type after indexing.

impl<E, B, I> Index<Range<I>> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity + PartialOrd
[src]

type Output = [E]

The returned type after indexing.

impl<E, B, I> Index<RangeFrom<I>> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity + PartialOrd
[src]

type Output = [E]

The returned type after indexing.

impl<E, B, I> Index<RangeFull> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity + PartialOrd
[src]

type Output = [E]

The returned type after indexing.

impl<E, B, I> Index<RangeInclusive<I>> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity + PartialOrd
[src]

type Output = [E]

The returned type after indexing.

impl<E, B, I> Index<RangeTo<I>> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity + PartialOrd
[src]

type Output = [E]

The returned type after indexing.

impl<E, B, I> Index<RangeToInclusive<I>> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity + PartialOrd
[src]

type Output = [E]

The returned type after indexing.

impl<E, B, I> IndexMut<I> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity
[src]

impl<E, B, I> IndexMut<Range<I>> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity + PartialOrd
[src]

impl<E, B, I> IndexMut<RangeFrom<I>> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity + PartialOrd
[src]

impl<E, B, I> IndexMut<RangeFull> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity + PartialOrd
[src]

impl<E, B, I> IndexMut<RangeInclusive<I>> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity + PartialOrd
[src]

impl<E, B, I> IndexMut<RangeTo<I>> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity + PartialOrd
[src]

impl<E, B, I> IndexMut<RangeToInclusive<I>> for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity + PartialOrd
[src]

impl<E, B, I> IntoIterator for Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity
[src]

type Item = E

The type of the elements being iterated over.

type IntoIter = IntoIterator<E, B, I>

Which kind of iterator are we turning this into?

impl<'a, E, B, I> IntoIterator for &'a Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity
[src]

type Item = &'a E

The type of the elements being iterated over.

type IntoIter = Iter<'a, E>

Which kind of iterator are we turning this into?

impl<'a, E, B, I> IntoIterator for &'a mut Vec<E, B, I> where
    B: ContiguousStorage<E>,
    I: Capacity
[src]

type Item = &'a mut E

The type of the elements being iterated over.

type IntoIter = IterMut<'a, E>

Which kind of iterator are we turning this into?

impl<E, B, I> Ord for Vec<E, B, I> where
    E: Ord,
    B: ContiguousStorage<E>,
    I: Capacity
[src]

impl<V, E, B, I> PartialEq<&'_ [V]> for Vec<E, B, I> where
    E: PartialEq<V>,
    B: ContiguousStorage<E>,
    I: Capacity
[src]

impl<V, E, B, I> PartialEq<&'_ mut [V]> for Vec<E, B, I> where
    E: PartialEq<V>,
    B: ContiguousStorage<E>,
    I: Capacity
[src]

impl<V, E, B, I, const N: usize> PartialEq<[V; N]> for Vec<E, B, I> where
    E: PartialEq<V>,
    B: ContiguousStorage<E>,
    I: Capacity
[src]

This is supported on crate feature nightly only.

impl<AE, AB, AI, BE, BB, BI> PartialEq<Vec<BE, BB, BI>> for Vec<AE, AB, AI> where
    AE: PartialEq<BE>,
    AB: ContiguousStorage<AE>,
    BB: ContiguousStorage<BE>,
    AI: Capacity,
    BI: Capacity
[src]

impl<V, E, B, I> PartialEq<Vec<E, B, I>> for &[V] where
    V: PartialEq<E>,
    B: ContiguousStorage<E>,
    I: Capacity
[src]

impl<V, E, B, I> PartialEq<Vec<E, B, I>> for &mut [V] where
    V: PartialEq<E>,
    B: ContiguousStorage<E>,
    I: Capacity
[src]

impl<V, E, B, I, const N: usize> PartialEq<Vec<E, B, I>> for [V; N] where
    V: PartialEq<E>,
    B: ContiguousStorage<E>,
    I: Capacity
[src]

This is supported on crate feature nightly only.

impl<E, B, I> PartialOrd<Vec<E, B, I>> for Vec<E, B, I> where
    E: PartialOrd,
    B: ContiguousStorage<E>,
    I: Capacity
[src]

Auto Trait Implementations

impl<Element, Buf, Idx> Send for Vec<Element, Buf, Idx> where
    Buf: Send,
    Element: Send,
    Idx: Send
[src]

impl<Element, Buf, Idx> Sync for Vec<Element, Buf, Idx> where
    Buf: Sync,
    Element: Sync,
    Idx: Sync
[src]

impl<Element, Buf, Idx> Unpin for Vec<Element, Buf, Idx> where
    Buf: Unpin,
    Element: Unpin,
    Idx: Unpin
[src]

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<!> for T[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.