[−][src]Struct mediumvec::vec32::Vec32
A vector that is indexed by u32 instead of usize.
On 32-bit platforms, Vec32<T> is mostly identical to the standard library Vec<T>.
On 64-bit platforms, the Vec32<T> struct takes up less space than the standard Vec<T>
struct (16 bytes instead of 24 bytes), but its maximum capacity is u32::MAX instead of
usize::MAX.
Warning
This type does not yet support 16-bit or 8-bit platforms. It may cause undefined behavior if used on any architecture with addresses smaller than 32 bits.
Examples
use mediumvec::Vec32; let mut vec = Vec32::new(); vec.push(1); vec.push(2); assert_eq!(vec.len(), 2); assert_eq!(vec[0], 1); assert_eq!(vec.pop(), Some(2)); assert_eq!(vec.len(), 1); vec[0] = 7; assert_eq!(vec[0], 7); vec.extend([1, 2, 3].iter().cloned()); assert_eq!(vec, [7, 1, 2, 3]);
The vec32! macro provides convenient initialization:
#[macro_use] extern crate mediumvec; fn main() { let mut vec = vec32![1, 2, 3]; assert_eq!(vec, [1, 2, 3]); let vec = vec32![0; 5]; assert_eq!(vec, vec32![0, 0, 0, 0, 0]); }
Implementations
impl<T> Vec32<T>[src]
pub fn new() -> Vec32<T>[src]
Constructs a new, empty vector.
The vector will not allocate until elements are pushed onto it.
pub fn with_capacity(cap: u32) -> Vec32<T>[src]
Constructs a new, empty (length 0) vector with the specified capacity.
pub fn push(&mut self, value: T)[src]
Append an element to the vector.
Panics if the number of elements in the vector overflows u32.
pub fn pop(&mut self) -> Option<T>[src]
Remove the last element from a vector and return it, or None if it is empty.
pub fn remove(&mut self, index: u32) -> T[src]
Remove and return the element at position index, shifting elements after it to the left.
Panics if index is out of bounds.
Examples
let mut v = vec32![1, 2, 3]; assert_eq!(v.remove(1), 2); assert_eq!(v, [1, 3]);
pub fn insert(&mut self, index: u32, element: T)[src]
Insert an element at position index, shifting elements after it to the right.
Panics if index is out of bounds or the length of the vector overflows u32.
Examples
let mut vec = vec![1, 2, 3]; vec.insert(1, 4); assert_eq!(vec, [1, 4, 2, 3]); vec.insert(4, 5); assert_eq!(vec, [1, 4, 2, 3, 5]);
pub fn reserve(&mut self, additional: u32)[src]
Reserve capacity for at least additional more elements to be inserted.
May reserve more space than requested, to avoid frequent reallocations.
Panics if the new capacity overflows u32.
Re-allocates only if self.capacity() < self.len() + additional.
pub fn reserve_exact(&mut self, additional: u32)[src]
Reserves the minimum capacity for additional more elements to be inserted.
Panics if the new capacity overflows u32.
Re-allocates only if self.capacity() < self.len() + additional.
pub fn from_vec(vec: Vec<T>) -> Vec32<T>[src]
Converts a Vec<T> to a Vec32<T>.
Panics if the vector's length is greater than u32::MAX.
Re-allocates only if the vector's capacity is greater than u32::MAX.
pub fn into_vec(self) -> Vec<T>[src]
Convert a Vec32<T> into a Vec<T> without re-allocating.
pub fn as_vec<F>(&mut self, f: F) where
F: FnOnce(&mut Vec<T>), [src]
F: FnOnce(&mut Vec<T>),
Convert a Vec32<T> into a Vec<T>, mutate it, then convert it back.
This is a convenient way to call Vec methods that don't have Vec32 equivalents.
Panics if the vector's length increases to greater than u32::MAX.
let mut v = vec32![0, 0, 0, 1, 1, 2, 3, 3, 3]; v.as_vec(|vec| vec.dedup()); assert_eq!(v, [0, 1, 2, 3]);
pub fn capacity(&self) -> u32[src]
Returns the maximum number of elements the vector can hold without reallocating.
pub fn clear(&mut self)[src]
Clears the vector, removing all values.
Note that this method has no effect on the allocated capacity of the vector.
pub fn truncate(&mut self, len: u32)[src]
Shorten 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.
Trait Implementations
impl<T> AsMut<[T]> for Vec32<T>[src]
impl<T> AsMut<Vec32<T>> for Vec32<T>[src]
impl<T> AsRef<[T]> for Vec32<T>[src]
impl<T> AsRef<Vec32<T>> for Vec32<T>[src]
impl<T> Borrow<[T]> for Vec32<T>[src]
impl<T> BorrowMut<[T]> for Vec32<T>[src]
fn borrow_mut(&mut self) -> &mut [T][src]
impl<T: Clone> Clone for Vec32<T>[src]
fn clone(&self) -> Self[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
impl<T: Debug> Debug for Vec32<T>[src]
impl<T> Default for Vec32<T>[src]
impl<T> Deref for Vec32<T>[src]
impl<T> DerefMut for Vec32<T>[src]
impl<T> Drop for Vec32<T>[src]
impl<T: Eq> Eq for Vec32<T>[src]
impl<T> Extend<T> for Vec32<T>[src]
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)[src]
fn extend_one(&mut self, item: A)[src]
fn extend_reserve(&mut self, additional: usize)[src]
impl<T> FromIterator<T> for Vec32<T>[src]
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Vec32<T>[src]
impl<T, I: SliceIndex<[T]>> Index<I> for Vec32<T>[src]
type Output = I::Output
The returned type after indexing.
fn index(&self, index: I) -> &Self::Output[src]
impl<T, I: SliceIndex<[T]>> IndexMut<I> for Vec32<T>[src]
impl<T> IntoIterator for Vec32<T>[src]
type Item = T
The type of the elements being iterated over.
type IntoIter = IntoIter<T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> IntoIter<T>[src]
impl<'a, T> IntoIterator for &'a Vec32<T>[src]
type Item = &'a T
The type of the elements being iterated over.
type IntoIter = Iter<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> Iter<'a, T>[src]
impl<'a, T> IntoIterator for &'a mut Vec32<T>[src]
type Item = &'a mut T
The type of the elements being iterated over.
type IntoIter = IterMut<'a, T>
Which kind of iterator are we turning this into?
fn into_iter(self) -> IterMut<'a, T>[src]
impl<T: Ord> Ord for Vec32<T>[src]
fn cmp(&self, other: &Vec32<T>) -> Ordering[src]
#[must_use]fn max(self, other: Self) -> Self1.21.0[src]
#[must_use]fn min(self, other: Self) -> Self1.21.0[src]
#[must_use]fn clamp(self, min: Self, max: Self) -> Self[src]
impl<T, U> PartialEq<U> for Vec32<T> where
U: for<'a> PartialEq<&'a [T]>, [src]
U: for<'a> PartialEq<&'a [T]>,
impl<T: PartialOrd> PartialOrd<Vec32<T>> for Vec32<T>[src]
fn partial_cmp(&self, other: &Vec32<T>) -> Option<Ordering>[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool1.0.0[src]
impl<T: Send> Send for Vec32<T>[src]
impl<T: Sync> Sync for Vec32<T>[src]
Auto Trait Implementations
impl<T> RefUnwindSafe for Vec32<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Unpin for Vec32<T>
impl<T> UnwindSafe for Vec32<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized, [src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized, [src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T[src]
impl<T> From<T> for T[src]
impl<T, U> Into<U> for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
pub fn to_owned(&self) -> T[src]
pub fn clone_into(&self, target: &mut 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.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>, [src]
U: TryFrom<T>,