[−][src]Struct sized_vec::Vec
A vector of length N
containing elements of type A
.
Methods
impl<A> Vec<U0, A>
[src]
impl<N, A> Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
#[must_use]
pub fn fill<F>(f: F) -> Vec<N, A> where
F: FnMut(usize) -> A,
[src]
F: FnMut(usize) -> A,
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]
A: Clone,
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]
I: IntoIterator<Item = A>,
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]
A: Default,
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]
N: Add<B1>,
Add1<N>: Unsigned,
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);
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]
N: Sub<U1>,
Diff<N, U1>: Unsigned,
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);
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]
Index: Unsigned + IsLess<N>,
Le<Index, N>: IsTrue,
N: Add<B1>,
Add1<N>: Unsigned,
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]
Index: Unsigned + IsLess<N>,
Le<Index, N>: IsTrue,
N: Sub<B1>,
Sub1<N>: Unsigned,
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]
Index: Unsigned + IsLess<N>,
Le<Index, N>: IsTrue,
N: Sub<B1>,
Sub1<N>: Unsigned,
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]
N: Add<M>,
M: Unsigned,
Sum<N, M>: Unsigned,
Append two vectors together.
#[must_use]
pub fn get<Index>(&self, _: Index) -> &A where
Index: Unsigned + IsLess<N>,
Le<Index, N>: IsTrue,
[src]
Index: Unsigned + IsLess<N>,
Le<Index, N>: IsTrue,
Get a reference to the element at index Index
.
Examples
let vec = svec![1, 2, 3]; assert_eq!(&2, vec.get(U1::new()));
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]
Index: Unsigned + IsLess<N>,
Le<Index, N>: IsTrue,
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]
N: IsEqual<U0>,
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]
M: Unsigned + IsLessOrEqual<N>,
LeEq<M, N>: IsTrue,
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]
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,
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]
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,
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]
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,
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]
M: Unsigned,
A: Clone,
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]
F: FnMut(A) -> B,
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]
F: FnMut(A) -> B,
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]
F: FnMut(A, B) -> C,
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]
F: FnMut(A) -> (B, C),
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: Eq, A: Eq> Eq for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
impl<N: PartialOrd, A: PartialOrd> PartialOrd<Vec<N, A>> for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
fn partial_cmp(&self, other: &Vec<N, A>) -> Option<Ordering>
[src]
fn lt(&self, other: &Vec<N, A>) -> bool
[src]
fn le(&self, other: &Vec<N, A>) -> bool
[src]
fn gt(&self, other: &Vec<N, A>) -> bool
[src]
fn ge(&self, other: &Vec<N, A>) -> bool
[src]
impl<N, A> AsMut<[A]> for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
impl<N, A> AsMut<Vec<N, A>> for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
impl<N: PartialEq, A: PartialEq> PartialEq<Vec<N, A>> for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
impl<N, A> AsRef<[A]> for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
impl<N, A> AsRef<Vec<N, A>> for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
impl<N, A> AsRef<Vec<A>> for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
impl<N: Clone, A: Clone> Clone for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
fn clone(&self) -> Vec<N, A>
[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<N: Ord, A: Ord> Ord for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
fn cmp(&self, other: &Vec<N, A>) -> Ordering
[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]
clamp
)Restrict a value to a certain interval. Read more
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> IntoIterator for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
type Item = A
The type of the elements being iterated over.
type IntoIter = IntoIter<A>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, N, A> IntoIterator for &'a Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<'a, N, A> IntoIterator for &'a mut Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
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?
fn into_iter(self) -> Self::IntoIter
[src]
impl<N, A> Into<Vec<A>> for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
impl<'a, N, A> Into<&'a [A]> for &'a Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
impl<'a, N, A> Into<&'a mut [A]> for &'a mut Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
fn into(self) -> &'a mut [A]
[src]
impl<N, A> Debug for Vec<N, A> where
N: Unsigned,
A: Debug,
[src]
N: Unsigned,
A: Debug,
impl<N: Hash, A: Hash> Hash for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
fn hash<__HNA: Hasher>(&self, state: &mut __HNA)
[src]
default fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
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]
N: Unsigned + Add<M>,
M: Unsigned,
Sum<N, M>: Unsigned,
type Output = Vec<Sum<N, M>, A>
The resulting type after applying the +
operator.
fn add(self, other: Vec<M, A>) -> Self::Output
[src]
impl<N, A, I> Index<I> for Vec<N, A> where
N: Unsigned,
I: Unsigned + IsLess<N>,
Le<I, N>: IsTrue,
[src]
N: Unsigned,
I: Unsigned + IsLess<N>,
Le<I, N>: IsTrue,
impl<N, A, I> IndexMut<I> for Vec<N, A> where
N: Unsigned,
I: Unsigned + IsLess<N>,
Le<I, N>: IsTrue,
[src]
N: Unsigned,
I: Unsigned + IsLess<N>,
Le<I, N>: IsTrue,
impl<N, A> TryFrom<Vec<A>> for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
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]
N: Unsigned,
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]
A: Clone,
N: Unsigned,
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]
N: Unsigned,
impl<N, A> Borrow<Vec<A>> for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
impl<N, A> BorrowMut<[A]> for Vec<N, A> where
N: Unsigned,
[src]
N: Unsigned,
fn borrow_mut(&mut self) -> &mut [A]
[src]
Auto Trait Implementations
impl<N, A> Send for Vec<N, A> where
A: Send,
N: Send,
A: Send,
N: Send,
impl<N, A> Sync for Vec<N, A> where
A: Sync,
N: Sync,
A: Sync,
N: Sync,
Blanket Implementations
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
impl<T> From for T
[src]
impl<I> IntoIterator for I where
I: Iterator,
[src]
I: Iterator,
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?
fn into_iter(self) -> I
[src]
impl<T, U> Into for T where
U: From<T>,
[src]
U: From<T>,
impl<T, U> TryFrom 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> Borrow for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> BorrowMut for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T, U> TryInto 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> Same for T
[src]
type Output = T
Should always be Self