[−][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]); }
Methods
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> Extend<T> for Vec32<T>[src]
fn extend<I: IntoIterator<Item = T>>(&mut self, iter: I)[src]
impl<T> Drop for Vec32<T>[src]
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]
This method tests less than (for self and other) and is used by the < operator. Read more
#[must_use]
fn le(&self, other: &Rhs) -> bool1.0.0[src]
This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
#[must_use]
fn gt(&self, other: &Rhs) -> bool1.0.0[src]
This method tests greater than (for self and other) and is used by the > operator. Read more
#[must_use]
fn ge(&self, other: &Rhs) -> bool1.0.0[src]
This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
impl<T, U> PartialEq<U> for Vec32<T> where
U: for<'a> PartialEq<&'a [T]>, [src]
U: for<'a> PartialEq<&'a [T]>,
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: Clone> Clone for Vec32<T>[src]
fn clone(&self) -> Self[src]
fn clone_from(&mut self, source: &Self)1.0.0[src]
Performs copy-assignment from source. Read more
impl<T: Eq> Eq for Vec32<T>[src]
impl<T> DerefMut for Vec32<T>[src]
impl<T: Debug> Debug for Vec32<T>[src]
impl<T> Deref for Vec32<T>[src]
impl<T> FromIterator<T> for Vec32<T>[src]
fn from_iter<I: IntoIterator<Item = T>>(iter: I) -> Vec32<T>[src]
Auto Trait Implementations
Blanket Implementations
impl<T, U> Into for T where
U: From<T>, [src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone, [src]
T: Clone,
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> From for T[src]
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> 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> Any for T where
T: 'static + ?Sized, [src]
T: 'static + ?Sized,