Primitive Type slice
Utilities for vector manipulation
The vec module contains useful code to help work with vector values.
Vectors are Rust's list type. Vectors contain zero or more values of
homogeneous types:
let int_vector = [1,2,3]; let str_vector = ["one", "two", "three"];
This is a big module, but for a high-level overview:
Structs
Several structs that are useful for vectors, such as Items, which
represents iteration over a vector.
Traits
A number of traits add methods that allow you to accomplish tasks with vectors.
Traits defined for the &[T] type (a vector slice), have methods that can be
called on either owned vectors, denoted ~[T], or on vector slices themselves.
These traits include ImmutableVector, and MutableVector for the &mut [T]
case.
An example is the method .slice(a, b) that returns an immutable "view" into
a vector or a vector slice from the index interval [a, b):
let numbers = [0, 1, 2]; let last_numbers = numbers.slice(1, 3); // last_numbers is now &[1, 2]
Traits defined for the ~[T] type, like OwnedVector, can only be called
on such vectors. These methods deal with adding elements or otherwise changing
the allocation of the vector.
An example is the method .push(element) that will add an element at the end
of the vector:
let mut numbers = vec![0, 1, 2]; numbers.push(7); // numbers is now vec![0, 1, 2, 7];
Implementations of other traits
Vectors are a very useful type, and so there's several implementations of traits from other modules. Some notable examples:
CloneEq,Ord,Eq,Ord-- vectors can be compared, if the element type defines the corresponding trait.
Iteration
The method iter() returns an iteration value for a vector or a vector slice.
The iterator yields references to the vector's elements, so if the element
type of the vector is int, the element type of the iterator is &int.
let numbers = [0i, 1i, 2i]; for &x in numbers.iter() { println!("{} is a number!", x); }
.mut_iter()returns an iterator that allows modifying each value..move_iter()converts an owned vector into an iterator that moves out a value from the vector each iteration.- Further iterators exist that split, chunk or permute the vector.
Function definitions
There are a number of free functions that create or take vectors, for example:
- Creating a vector, like
from_elemandfrom_fn - Creating a vector with a given size:
with_capacity - Modifying a vector and returning it, like
append - Operations on paired elements, like
unzip.
Trait Implementations
impl<'a> AsciiCast<&'a [Ascii]> for &'a [u8]
unsafe fn to_ascii_nocheck(&self) -> &'a [Ascii]
fn is_ascii(&self) -> bool
fn to_ascii(&self) -> T
fn to_ascii_opt(&self) -> Option<T>
impl<'a> AsciiStr for &'a [Ascii]
fn as_str_ascii<'a>(&'a self) -> &'a str
fn to_lower(&self) -> Vec<Ascii>
fn to_upper(&self) -> Vec<Ascii>
fn eq_ignore_case(self, other: &[Ascii]) -> bool
impl<'a, T> Clone for &'a [T]
fn clone<'a, T>(&self) -> &'a [T]
Return a shallow copy of the slice.
fn clone_from<'a, T>(&mut self, &&'a [T])
impl<'a, T> Repr<Slice<T>> for &'a [T]
impl<'a, T: PartialEq> PartialEq for &'a [T]
fn eq<'a, T: PartialEq>(&self, other: &&'a [T]) -> bool
fn ne<'a, T: PartialEq>(&self, other: &&'a [T]) -> bool
fn ne<'a, T: PartialEq>(&self, &&'a [T]) -> bool
impl<'a, T: Eq> Eq for &'a [T]
fn assert_receiver_is_total_eq<'a, T: Eq>(&self)
impl<'a, T: PartialEq, V: Vector<T>> Equiv<V> for &'a [T]
impl<'a, T: Ord> Ord for &'a [T]
impl<'a, T: PartialOrd> PartialOrd for &'a [T]
fn lt<'a, T: PartialOrd>(&self, other: &&'a [T]) -> bool
fn le<'a, T: PartialOrd>(&self, other: &&'a [T]) -> bool
fn ge<'a, T: PartialOrd>(&self, other: &&'a [T]) -> bool
fn gt<'a, T: PartialOrd>(&self, other: &&'a [T]) -> bool
fn le<'a, T: PartialOrd>(&self, &&'a [T]) -> bool
fn gt<'a, T: PartialOrd>(&self, &&'a [T]) -> bool
fn ge<'a, T: PartialOrd>(&self, &&'a [T]) -> bool
impl<'a, T> Vector<T> for &'a [T]
impl<'a, T> Collection for &'a [T]
impl<'a, T> ImmutableVector<'a, T> for &'a [T]
fn slice<'a, T>(&self, start: uint, end: uint) -> &'a [T]
fn slice_from<'a, T>(&self, start: uint) -> &'a [T]
fn slice_to<'a, T>(&self, end: uint) -> &'a [T]
fn iter<'a, T>(self) -> Items<'a, T>
fn split<'a, T>(self, pred: |&T|: 'a -> bool) -> Splits<'a, T>
fn splitn<'a, T>(self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<'a, T>
fn rsplitn<'a, T>(self, n: uint, pred: |&T|: 'a -> bool) -> SplitsN<'a, T>
fn windows<'a, T>(self, size: uint) -> Windows<'a, T>
fn chunks<'a, T>(self, size: uint) -> Chunks<'a, T>
fn get<'a, T>(&self, index: uint) -> Option<&'a T>
fn head<'a, T>(&self) -> Option<&'a T>
fn tail<'a, T>(&self) -> &'a [T]
fn tailn<'a, T>(&self, n: uint) -> &'a [T]
fn init<'a, T>(&self) -> &'a [T]
fn initn<'a, T>(&self, n: uint) -> &'a [T]
fn last<'a, T>(&self) -> Option<&'a T>
unsafe fn unsafe_ref<'a, T>(self, index: uint) -> &'a T
fn as_ptr<'a, T>(&self) -> *T
fn bsearch<'a, T>(&self, f: |&T| -> Ordering) -> Option<uint>
fn shift_ref<'a, T>(&mut self) -> Option<&'a T>
fn pop_ref<'a, T>(&mut self) -> Option<&'a T>
impl<'a, T: PartialEq> ImmutableEqVector<T> for &'a [T]
fn position_elem<'a, T: PartialEq>(&self, x: &T) -> Option<uint>
fn rposition_elem<'a, T: PartialEq>(&self, t: &T) -> Option<uint>
fn contains<'a, T: PartialEq>(&self, x: &T) -> bool
fn starts_with<'a, T: PartialEq>(&self, needle: &[T]) -> bool
fn ends_with<'a, T: PartialEq>(&self, needle: &[T]) -> bool
impl<'a, T: Ord> ImmutableOrdVector<T> for &'a [T]
fn bsearch_elem<'a, T: Ord>(&self, x: &T) -> Option<uint>
impl<'a, T> MutableVector<'a, T> for &'a mut [T]
fn get_mut<'a, T>(self, index: uint) -> Option<&'a mut T>
fn as_mut_slice<'a, T>(self) -> &'a mut [T]
fn mut_slice<'a, T>(self, start: uint, end: uint) -> &'a mut [T]
fn mut_slice_from<'a, T>(self, start: uint) -> &'a mut [T]
fn mut_slice_to<'a, T>(self, end: uint) -> &'a mut [T]
fn mut_split_at<'a, T>(self, mid: uint) -> (&'a mut [T], &'a mut [T])
fn mut_iter<'a, T>(self) -> MutItems<'a, T>
fn mut_last<'a, T>(self) -> Option<&'a mut T>
fn mut_split<'a, T>(self, pred: |&T|: 'a -> bool) -> MutSplits<'a, T>
fn mut_chunks<'a, T>(self, chunk_size: uint) -> MutChunks<'a, T>
fn mut_shift_ref<'a, T>(&mut self) -> Option<&'a mut T>
fn mut_pop_ref<'a, T>(&mut self) -> Option<&'a mut T>
fn swap<'a, T>(self, a: uint, b: uint)
fn reverse<'a, T>(self)
unsafe fn unsafe_mut_ref<'a, T>(self, index: uint) -> &'a mut T
fn as_mut_ptr<'a, T>(self) -> *mut T
unsafe fn unsafe_set<'a, T>(self, index: uint, val: T)
unsafe fn init_elem<'a, T>(self, i: uint, val: T)
unsafe fn copy_memory<'a, T>(self, src: &[T])
impl<'a, T: Clone> MutableCloneableVector<T> for &'a mut [T]
impl<'a> MutableByteVector for &'a mut [u8]
fn set_memory<'a>(self, value: u8)
impl<'a, T> Default for &'a [T]
impl<'a> CharEq for &'a [char]
fn matches<'a>(&mut self, c: char) -> bool
fn only_ascii<'a>(&self) -> bool
impl<'a, T: Show> Show for &'a [T]
fn fmt<'a, T: Show>(&self, f: &mut Formatter) -> Result<(), FormatError>
impl<'a, T: Show> Show for &'a mut [T]
fn fmt<'a, T: Show>(&self, f: &mut Formatter) -> Result<(), FormatError>
impl<'a, T: Clone, V: Vector<T>> VectorVector<T> for &'a [V]
fn concat_vec<'a, T: Clone, V: Vector<T>>(&self) -> Vec<T>
fn connect_vec<'a, T: Clone, V: Vector<T>>(&self, sep: &T) -> Vec<T>
impl<'a, T: Clone> CloneableVector<T> for &'a [T]
Extension methods for vector slices
fn to_owned<'a, T: Clone>(&self) -> Vec<T>
Returns a copy of v.