[][src]Struct sized_vec::Vec

pub struct Vec<N, A> where
    N: Unsigned
{ /* fields omitted */ }

A vector of length N containing elements of type A.

Methods

impl<A> Vec<U0, A>[src]

#[must_use]
pub fn new() -> Self
[src]

Construct an empty vector.

impl<N, A> Vec<N, A> where
    N: Unsigned
[src]

#[must_use]
pub fn fill<F>(f: F) -> Vec<N, A> where
    F: FnMut(usize) -> A, 
[src]

Construct a vector of size N using a function.

The function is called with an index to generate a value of A for each index in the vector.

Examples

let vec: Vec<U3, _> = Vec::fill(|i| i + 10);
assert_eq!(svec![10, 11, 12], vec);

#[must_use]
pub fn repeat(a: A) -> Vec<N, A> where
    A: Clone
[src]

Construct a vector of size N containing the same element repeated.

Examples

let vec: Vec<U3, _> = Vec::repeat(5);
assert_eq!(svec![5, 5, 5], vec);

#[must_use]
pub fn try_from<I>(iter: I) -> Option<Self> where
    I: IntoIterator<Item = A>, 
[src]

Construct a vector of size N from an iterator.

Returns None if the iterator didn't contain exactly N elements.

Examples

let good_vec: Option<Vec<U3, _>> = Vec::try_from(1..=3);
assert_eq!(Some(svec![1, 2, 3]), good_vec);

let bad_vec: Option<Vec<U3, _>> = Vec::try_from(1..=500);
assert_eq!(None, bad_vec);

#[must_use]
pub fn try_from_vec(vec: Vec<A>) -> Option<Self>
[src]

Construct a vector of size N from a std::vec::Vec.

Returns None if the source vector didn't contain exactly N elements.

This is functionally equivalent to Vec::try_from, but slightly faster.

Examples

let good_vec: Option<Vec<U3, _>> = Vec::try_from_vec(vec![1, 2, 3]);
assert_eq!(Some(svec![1, 2, 3]), good_vec);

let bad_vec: Option<Vec<U3, _>> = Vec::try_from_vec(vec![1, 2]);
assert_eq!(None, bad_vec);

#[must_use]
pub fn push(self, a: A) -> Vec<Add1<N>, A> where
    N: Add<B1>,
    Add1<N>: Unsigned
[src]

Push an element onto the end of the vector.

Examples

let vec: Vec<U2, _> = svec![1, 2];
let new_vec: Vec<U3, _> = vec.push(3);
assert_eq!(svec![1, 2, 3], new_vec);
This example deliberately fails to compile
let vec: Vec<U2, _> = svec![1, 2];
// Type error, because the new length will be U3, not U2:
let new_vec: Vec<U2, _> = vec.push(3);

#[must_use]
pub fn pop(self) -> (Vec<Diff<N, U1>, A>, A) where
    N: Sub<U1>,
    Diff<N, U1>: Unsigned
[src]

Pop an element off the end of the vector.

Examples

let vec = svec![1, 2, 3];
let (new_vec, value) = vec.pop();
assert_eq!(svec![1, 2], new_vec);
assert_eq!(3, value);
This example deliberately fails to compile
let vec: Vec<U3, _> = svec![1, 2, 3];
// Type error, because the new length will be U2, not U3:
let (new_vec: Vec<U3, _>, value) = vec.pop();

#[must_use]
pub fn insert<Index>(self, _: Index, a: A) -> Vec<Add1<N>, A> where
    Index: Unsigned + IsLess<N>,
    Le<Index, N>: IsTrue,
    N: Add<B1>,
    Add1<N>: Unsigned
[src]

Insert an element into the vector at index Index.

#[must_use]
pub fn remove<Index>(self, _: Index) -> (Vec<Sub1<N>, A>, A) where
    Index: Unsigned + IsLess<N>,
    Le<Index, N>: IsTrue,
    N: Sub<B1>,
    Sub1<N>: Unsigned
[src]

Remove the element at index Index from the vector.

#[must_use]
pub fn swap_remove<Index>(self, _: Index) -> (Vec<Sub1<N>, A>, A) where
    Index: Unsigned + IsLess<N>,
    Le<Index, N>: IsTrue,
    N: Sub<B1>,
    Sub1<N>: Unsigned
[src]

Remove the element at index Index from the vector, replacing it with the element at the end of the vector.

#[must_use]
pub fn append<M>(self, other: Vec<M, A>) -> Vec<Sum<N, M>, A> where
    N: Add<M>,
    M: Unsigned,
    Sum<N, M>: Unsigned
[src]

Append two vectors together.

#[must_use]
pub fn get<Index>(&self, _: Index) -> &A where
    Index: Unsigned + IsLess<N>,
    Le<Index, N>: IsTrue
[src]

Get a reference to the element at index Index.

Examples

let vec = svec![1, 2, 3];
assert_eq!(&2, vec.get(U1::new()));
This example deliberately fails to compile
let vec = svec![1, 2, 3];
// This index is out of bounds, so this won't compile:
assert_eq!(&2, vec.get(U5::new()));

#[must_use]
pub fn get_mut<Index>(&mut self, _: Index) -> &mut A where
    Index: Unsigned + IsLess<N>,
    Le<Index, N>: IsTrue
[src]

Get a mutable reference to the element at index Index.

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

Get the length of the vector.

#[must_use]
pub fn is_empty(&self) -> bool where
    N: IsEqual<U0>, 
[src]

Test if the vector is empty.

#[must_use]
pub fn iter(&self) -> Iter<A>
[src]

Get an iterator over the elements of the vector.

#[must_use]
pub fn iter_mut(&mut self) -> IterMut<A>
[src]

Get a mutable iterator over the elements of the vector.

#[must_use]
pub fn as_slice(&self) -> &[A]
[src]

Get a reference to the slice of elements contained in the vector.

#[must_use]
pub fn as_mut_slice(&mut self) -> &mut [A]
[src]

Get a mutable reference to the slice of elements contained in the vector.

#[must_use]
pub fn truncate<M>(self) -> Vec<M, A> where
    M: Unsigned + IsLessOrEqual<N>,
    LeEq<M, N>: IsTrue
[src]

Truncate the vector to fit the size given by the target type.

Examples

let vec_6 = svec![1, 2, 3, 4, 5, 6];
let vec_3: Vec<U3, _> = vec_6.truncate();
assert_eq!(svec![1, 2, 3], vec_3);

#[must_use]
pub fn slice<Left, Right>(
    self,
    _: Range<Left, Right>
) -> (Vec<Diff<N, Diff<Right, Left>>, A>, Vec<Diff<Right, Left>, A>) where
    Diff<N, Diff<Right, Left>>: Unsigned,
    Diff<Right, Left>: Unsigned,
    Left: Unsigned + IsLessOrEqual<Right>,
    Right: Unsigned + Sub<Left> + IsLessOrEqual<N>,
    N: Sub<Diff<Right, Left>>,
    LeEq<Left, Right>: IsTrue,
    LeEq<Right, N>: IsTrue
[src]

Slice a subset out of the vector.

Examples

let vec = svec![1, 2, 3, 4, 5, 6];
let (vec, sub_vec) = vec.slice(Range::<U2, U4>::new());
assert_eq!(svec![1, 2, 5, 6], vec);
assert_eq!(svec![3, 4], sub_vec);

#[must_use]
pub fn drain<Left, Right>(
    self,
    range: Range<Left, Right>
) -> (Vec<Diff<N, Diff<Right, Left>>, A>, impl Iterator<Item = A>) where
    Diff<N, Diff<Right, Left>>: Unsigned,
    Diff<Right, Left>: Unsigned,
    Left: Unsigned + IsLessOrEqual<Right>,
    Right: Unsigned + Sub<Left> + IsLessOrEqual<N>,
    N: Sub<Diff<Right, Left>>,
    LeEq<Left, Right>: IsTrue,
    LeEq<Right, N>: IsTrue
[src]

Remove a subset from the vector and return an iterator over the removed elements.

Examples

let vec = svec![1, 2, 3, 4, 5, 6];
let (vec, iter) = vec.drain(Range::<U2, U4>::new());
assert_eq!(svec![1, 2, 5, 6], vec);
assert_eq!(vec![3, 4], iter.collect::<::std::vec::Vec<_>>());

#[must_use]
pub fn clear(self) -> Vec<U0, A>
[src]

Drop the contents of the vector, leaving an empty vector.

#[must_use]
pub fn split_off<Index>(
    self,
    _: Index
) -> (Vec<Index, A>, Vec<Diff<N, Index>, A>) where
    Index: Unsigned + IsLessOrEqual<N>,
    N: Sub<Index>,
    Diff<N, Index>: Unsigned,
    LeEq<Index, N>: IsTrue
[src]

Split the vector at Index, returning the two sides of the split.

Examples

let vec = svec![1, 2, 3, 4, 5, 6];
let (left, right) = vec.split_off(U3::new());
assert_eq!(svec![1, 2, 3], left);
assert_eq!(svec![4, 5, 6], right);

#[must_use]
pub fn resize<M>(self, value: A) -> Vec<M, A> where
    M: Unsigned,
    A: Clone
[src]

Resize the vector, dropping elements if the new size is smaller, and padding with copies of value if it is larger.

Examples

let vec = svec![1, 2, 3];
let vec: Vec<U5, _> = vec.resize(100);
assert_eq!(svec![1, 2, 3, 100, 100], vec);

#[must_use]
pub fn map<F, B>(self, f: F) -> Vec<N, B> where
    F: FnMut(A) -> B, 
[src]

Map the vector into a vector of elements of B using a function.

Examples

let vec = svec![1, 2, 3];
let vec = vec.map(|num| format!("{}", num));
assert_eq!(svec![
    "1".to_string(), "2".to_string(), "3".to_string()
], vec);

#[must_use]
pub fn apply<F, B>(self, fs: Vec<N, F>) -> Vec<N, B> where
    F: FnMut(A) -> B, 
[src]

Apply a list of functions from A to B to a vector of A in order, returning a vector of B.

Examples

let vec = svec![1, 2, 3];
let fn_vec = vec.clone().map(|i| move |a| a + i);
let vec = vec.apply(fn_vec);
assert_eq!(svec![2, 4, 6], vec);

#[must_use]
pub fn zip<B, C, F>(self, other: Vec<N, B>, f: F) -> Vec<N, C> where
    F: FnMut(A, B) -> C, 
[src]

Merge two vectors together into a new vector using a function.

Examples

let left = svec!["foo", "bar"];
let right = svec!["lol", "omg"];
let vec = left.zip(right, |a, b| format!("{} {}", a, b));
assert_eq!(svec![
    "foo lol".to_string(), "bar omg".to_string()
], vec);

#[must_use]
pub fn unzip<B, C, F>(self, f: F) -> (Vec<N, B>, Vec<N, C>) where
    F: FnMut(A) -> (B, C)
[src]

Split a vector into two vectors of the same size using a function.

Examples

let left = svec!["foo", "bar"];
let right = svec!["lol", "omg"];
let vec = left.zip(right, |a, b| format!("{} {}", a, b));
assert_eq!(svec![
    "foo lol".to_string(), "bar omg".to_string()
], vec);

Trait Implementations

impl<N, A> IntoIterator for Vec<N, A> where
    N: Unsigned
[src]

type Item = A

The type of the elements being iterated over.

type IntoIter = IntoIter<A>

Which kind of iterator are we turning this into?

impl<'a, N, A> IntoIterator for &'a Vec<N, A> where
    N: Unsigned
[src]

type Item = &'a A

The type of the elements being iterated over.

type IntoIter = Iter<'a, A>

Which kind of iterator are we turning this into?

impl<'a, N, A> IntoIterator for &'a mut Vec<N, A> where
    N: Unsigned
[src]

type Item = &'a mut A

The type of the elements being iterated over.

type IntoIter = IterMut<'a, A>

Which kind of iterator are we turning this into?

impl<N: Eq, A: Eq> Eq for Vec<N, A> where
    N: Unsigned
[src]

impl<N: Clone, A: Clone> Clone for Vec<N, A> where
    N: Unsigned
[src]

fn clone_from(&mut self, source: &Self)
1.0.0
[src]

Performs copy-assignment from source. Read more

impl<N, A> Into<Vec<A>> for Vec<N, A> where
    N: Unsigned
[src]

impl<'a, N, A> Into<&'a [A]> for &'a Vec<N, A> where
    N: Unsigned
[src]

impl<N: PartialOrd, A: PartialOrd> PartialOrd<Vec<N, A>> for Vec<N, A> where
    N: Unsigned
[src]

impl<N, A> AsMut<[A]> for Vec<N, A> where
    N: Unsigned
[src]

impl<N, A> AsMut<Vec<N, A>> for Vec<N, A> where
    N: Unsigned
[src]

impl<N: PartialEq, A: PartialEq> PartialEq<Vec<N, A>> for Vec<N, A> where
    N: Unsigned
[src]

impl<N, A> AsRef<[A]> for Vec<N, A> where
    N: Unsigned
[src]

impl<N, A> AsRef<Vec<N, A>> for Vec<N, A> where
    N: Unsigned
[src]

impl<A> Default for Vec<U0, A>[src]

impl<N: Ord, A: Ord> Ord for Vec<N, A> where
    N: Unsigned
[src]

fn max(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the maximum of two values. Read more

fn min(self, other: Self) -> Self
1.21.0
[src]

Compares and returns the minimum of two values. Read more

impl<N: Hash, A: Hash> Hash for Vec<N, A> where
    N: Unsigned
[src]

fn hash_slice<H>(data: &[Self], state: &mut H) where
    H: Hasher
1.3.0
[src]

Feeds a slice of this type into the given [Hasher]. Read more

impl<N, M, A> Add<Vec<M, A>> for Vec<N, A> where
    N: Unsigned + Add<M>,
    M: Unsigned,
    Sum<N, M>: Unsigned
[src]

type Output = Vec<Sum<N, M>, A>

The resulting type after applying the + operator.

impl<N, A, I> Index<I> for Vec<N, A> where
    N: Unsigned,
    I: Unsigned + IsLess<N>,
    Le<I, N>: IsTrue
[src]

type Output = A

The returned type after indexing.

impl<N, A, I> IndexMut<I> for Vec<N, A> where
    N: Unsigned,
    I: Unsigned + IsLess<N>,
    Le<I, N>: IsTrue
[src]

impl<N, A> Debug for Vec<N, A> where
    N: Unsigned,
    A: Debug
[src]

impl<N, A> Borrow<[A]> for Vec<N, A> where
    N: Unsigned
[src]

impl<N, A> BorrowMut<[A]> for Vec<N, A> where
    N: Unsigned
[src]

Auto Trait Implementations

impl<N, A> Send for Vec<N, A> where
    A: Send,
    N: Send

impl<N, A> Sync for Vec<N, A> where
    A: Sync,
    N: Sync

Blanket Implementations

impl<I> IntoIterator for I where
    I: Iterator
[src]

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?

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

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

type Owned = T

impl<T> From for T[src]

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

type Error = !

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

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

🔬 This is a nightly-only experimental API. (try_from)

The type returned in the event of a conversion error.

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

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

impl<T> Same for T[src]

type Output = T

Should always be Self