[][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_iter<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_iter(1..=3);
assert_eq!(Some(svec![1, 2, 3]), good_vec);

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

#[must_use]
pub fn from_default() -> Vec<N, A> where
    A: Default
[src]

Construct a vector of size N using the default value.

Examples

let vec: Vec<U3, _> = Vec::from_default();
assert_eq!(svec![0, 0, 0], 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 vec = svec![1, 2, 3];
let vec = vec.unzip(|a| (a, a * 2));
assert_eq!((svec![1, 2, 3], svec![2, 4, 6]), vec);

Trait Implementations

impl<N: PartialOrd, A: PartialOrd> PartialOrd<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: Eq, A: Eq> Eq for Vec<N, A> where
    N: Unsigned
[src]

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

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

Compares and returns the maximum of two values. Read more

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

Compares and returns the minimum of two values. Read more

default fn clamp(self, min: Self, max: Self) -> Self[src]

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

Restrict a value to a certain interval. Read more

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, 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: Clone, A: Clone> Clone for Vec<N, A> where
    N: Unsigned
[src]

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

Performs copy-assignment from source. Read more

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

impl<A> From<[A; 0]> for Vec<U0, A>[src]

impl<A> From<[A; 1]> for Vec<U1, A>[src]

impl<A> From<[A; 2]> for Vec<U2, A>[src]

impl<A> From<[A; 3]> for Vec<U3, A>[src]

impl<A> From<[A; 4]> for Vec<U4, A>[src]

impl<A> From<[A; 5]> for Vec<U5, A>[src]

impl<A> From<[A; 6]> for Vec<U6, A>[src]

impl<A> From<[A; 7]> for Vec<U7, A>[src]

impl<A> From<[A; 8]> for Vec<U8, A>[src]

impl<A> From<[A; 9]> for Vec<U9, A>[src]

impl<A> From<[A; 10]> for Vec<U10, A>[src]

impl<A> From<[A; 11]> for Vec<U11, A>[src]

impl<A> From<[A; 12]> for Vec<U12, A>[src]

impl<A> From<[A; 13]> for Vec<U13, A>[src]

impl<A> From<[A; 14]> for Vec<U14, A>[src]

impl<A> From<[A; 15]> for Vec<U15, A>[src]

impl<A> From<[A; 16]> for Vec<U16, A>[src]

impl<A> From<[A; 17]> for Vec<U17, A>[src]

impl<A> From<[A; 18]> for Vec<U18, A>[src]

impl<A> From<[A; 19]> for Vec<U19, A>[src]

impl<A> From<[A; 20]> for Vec<U20, A>[src]

impl<A> From<[A; 21]> for Vec<U21, A>[src]

impl<A> From<[A; 22]> for Vec<U22, A>[src]

impl<A> From<[A; 23]> for Vec<U23, A>[src]

impl<A> From<[A; 24]> for Vec<U24, A>[src]

impl<A> From<[A; 25]> for Vec<U25, A>[src]

impl<A> From<[A; 26]> for Vec<U26, A>[src]

impl<A> From<[A; 27]> for Vec<U27, A>[src]

impl<A> From<[A; 28]> for Vec<U28, A>[src]

impl<A> From<[A; 29]> for Vec<U29, A>[src]

impl<A> From<[A; 30]> for Vec<U30, A>[src]

impl<A> From<[A; 31]> for Vec<U31, A>[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<N, A> AsRef<Vec<A>> for Vec<N, A> where
    N: Unsigned
[src]

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<'a, N, A> Into<&'a mut [A]> for &'a mut Vec<N, A> where
    N: Unsigned
[src]

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

default 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> TryFrom<Vec<A>> for Vec<N, A> where
    N: Unsigned
[src]

type Error = ()

The type returned in the event of a conversion error.

#[must_use]
fn try_from(vec: Vec<A>) -> Result<Self, Self::Error>
[src]

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

Returns Err(()) if the source vector didn't contain exactly N elements.

Examples

let good_vec: Result<Vec<U3, _>, _> = Vec::try_from(vec![1, 2, 3]);
assert_eq!(Ok(svec![1, 2, 3]), good_vec);

let bad_vec: Result<Vec<U3, _>, _> = Vec::try_from(vec![1, 2]);
assert_eq!(Err(()), bad_vec);

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

type Error = ()

The type returned in the event of a conversion error.

#[must_use]
fn try_from(array: Box<[A]>) -> Result<Self, Self::Error>
[src]

Construct a vector of size N from a boxed array.

Returns Err(()) if the source vector didn't contain exactly N elements.

Examples

let boxed: Box<[_]> = Box::new([1, 2, 3]);
let good_vec: Result<Vec<U3, _>, _> = Vec::try_from(boxed);
assert_eq!(Ok(svec![1, 2, 3]), good_vec);

let boxed: Box<[_]> = Box::new([1, 2]);
let bad_vec: Result<Vec<U3, _>, _> = Vec::try_from(boxed);
assert_eq!(Err(()), bad_vec);

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

type Error = ()

The type returned in the event of a conversion error.

#[must_use]
fn try_from(slice: &'a [A]) -> Result<Self, Self::Error>
[src]

Construct a vector of size N from a slice of clonable values.

Returns Err(()) if the source slice didn't contain exactly N elements.

Examples

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

let bad_vec: Result<Vec<U3, _>, _> = Vec::try_from([1, 2].as_ref());
assert_eq!(Err(()), bad_vec);

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

impl<N, A> Borrow<Vec<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> From for T[src]

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, U> TryFrom for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

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

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

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

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

The type returned in the event of a conversion error.

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

impl<T> Same for T[src]

type Output = T

Should always be Self