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 VecIterator, which represents iteration over a vector.

Traits

A number of traits that allow you to accomplish tasks with vectors, like the MutableVector and ImmutableVector traits.

Implementations of other traits

Vectors are a very useful type, and so there's tons of implementations of traits found elsewhere. Some notable examples:

Function definitions

There are a number of different functions that take vectors, here are some broad categories:

And much, much more.

Type MutRevIterator

type MutRevIterator<'self, T> = Invert<VecMutIterator<'self, T>>

Type RevIterator

type RevIterator<'self, T> = Invert<VecIterator<'self, T>>

Struct ChunkIter

pub struct ChunkIter<'self, T> {
    priv v: &'self [T],
    priv size: uint,
}

An iterator over a vector in (non-overlapping) chunks (size elements at a time).

When the vector len is not evenly divided by the chunk size, the last slice of the iteration will be the remainder.

Struct MoveIterator

pub struct MoveIterator<T> {
    priv v: ~[T],
    priv idx: uint,
}

An iterator that moves out of a vector.

Struct MoveRevIterator

pub struct MoveRevIterator<T> {
    priv v: ~[T],
}

An iterator that moves out of a vector in reverse order.

Struct RSplitIterator

pub struct RSplitIterator<'self, T> {
    priv v: &'self [T],
    priv n: uint,
    priv pred: &'self fn(t: &T) -> bool,
    priv finished: bool,
}

An iterator over the slices of a vector separated by elements that match a predicate function, from back to front.

Struct SplitIterator

pub struct SplitIterator<'self, T> {
    priv v: &'self [T],
    priv n: uint,
    priv pred: &'self fn(t: &T) -> bool,
    priv finished: bool,
}

An iterator over the slices of a vector separated by elements that match a predicate function.

Struct VecIterator

pub struct VecIterator<'self, T> {
    priv ptr: *T,
    priv end: *T,
    priv lifetime: &'self T,
}

An iterator for iterating over a vector.

Struct VecMutIterator

pub struct VecMutIterator<'self, T> {
    priv ptr: *mut T,
    priv end: *mut T,
    priv lifetime: &'self mut T,
}

An iterator for mutating the elements of a vector.

Struct WindowIter

pub struct WindowIter<'self, T> {
    priv v: &'self [T],
    priv size: uint,
}

An iterator over the (overlapping) slices of length size within a vector.

Trait CopyableVector

Extension methods for vector slices with copyable elements

Method to_owned

fn to_owned(&self) -> ~[T]

Copy self into a new owned vector

Method into_owned

fn into_owned(self) -> ~[T]

Convert self into a owned vector, not making a copy if possible.

Trait ImmutableCopyableVector

Method partitioned

fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T])

Method unsafe_get

unsafe fn unsafe_get(&self, elem: uint) -> T

Trait ImmutableEqVector

Method position_elem

fn position_elem(&self, t: &T) -> Option<uint>

Method rposition_elem

fn rposition_elem(&self, t: &T) -> Option<uint>

Method contains

fn contains(&self, x: &T) -> bool

Trait ImmutableTotalOrdVector

Method bsearch_elem

fn bsearch_elem(&self, x: &T) -> Option<uint>

Trait ImmutableVector

Method slice

fn slice(&self, start: uint, end: uint) -> &'self [T]

Method slice_from

fn slice_from(&self, start: uint) -> &'self [T]

Method slice_to

fn slice_to(&self, end: uint) -> &'self [T]

Method iter

fn iter(self) -> VecIterator<'self, T>

Method rev_iter

fn rev_iter(self) -> RevIterator<'self, T>

Method split_iter

fn split_iter(self, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T>

Method splitn_iter

fn splitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) ->
 SplitIterator<'self, T>

Method rsplit_iter

fn rsplit_iter(self, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T>

Method rsplitn_iter

fn rsplitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) ->
 RSplitIterator<'self, T>

Method window_iter

fn window_iter(self, size: uint) -> WindowIter<'self, T>

Method chunk_iter

fn chunk_iter(self, size: uint) -> ChunkIter<'self, T>

Method head

fn head(&self) -> &'self T

Method head_opt

fn head_opt(&self) -> Option<&'self T>

Method tail

fn tail(&self) -> &'self [T]

Method tailn

fn tailn(&self, n: uint) -> &'self [T]

Method init

fn init(&self) -> &'self [T]

Method initn

fn initn(&self, n: uint) -> &'self [T]

Method last

fn last(&self) -> &'self T

Method last_opt

fn last_opt(&self) -> Option<&'self T>

Method flat_map

fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U]

Method unsafe_ref

unsafe fn unsafe_ref(&self, index: uint) -> *T

Method bsearch

fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option<uint>

Method map

fn map<U>(&self, &fn(t: &T) -> U) -> ~[U]

Method as_imm_buf

fn as_imm_buf<U>(&self, f: &fn(*T, uint) -> U) -> U

Trait MutableCloneableVector

Trait for &[T] where T is Cloneable

Method copy_from

fn copy_from(self, &[T]) -> uint

Copies as many elements from src as it can into self (the shorter of self.len() and src.len()). Returns the number of elements copied.

Trait MutableVector

Method mut_slice

fn mut_slice(self, start: uint, end: uint) -> &'self mut [T]

Method mut_slice_from

fn mut_slice_from(self, start: uint) -> &'self mut [T]

Method mut_slice_to

fn mut_slice_to(self, end: uint) -> &'self mut [T]

Method mut_iter

fn mut_iter(self) -> VecMutIterator<'self, T>

Method mut_rev_iter

fn mut_rev_iter(self) -> MutRevIterator<'self, T>

Method swap

fn swap(self, a: uint, b: uint)

Method mut_split

fn mut_split(self, mid: uint) -> (&'self mut [T], &'self mut [T])

Divides one &mut into two. The first will contain all indices from 0..mid (excluding the index mid itself) and the second will contain all indices from mid..len (excluding the index len itself).

Method reverse

fn reverse(self)

Method move_from

fn move_from(self, src: ~[T], start: uint, end: uint) -> uint

Consumes src and moves as many elements as it can into self from the range [start,end).

Returns the number of elements copied (the shorter of self.len() and end - start).

Arguments

  • src - A mutable vector of T
  • start - The index into src to start copying from
  • end - The index into str to stop copying from

Method unsafe_mut_ref

unsafe fn unsafe_mut_ref(self, index: uint) -> *mut T

Method unsafe_set

unsafe fn unsafe_set(self, index: uint, val: T)

Method as_mut_buf

fn as_mut_buf<U>(self, f: &fn(*mut T, uint) -> U) -> U

Trait OwnedCopyableVector

Method push_all

fn push_all(&mut self, rhs: &[T])

Method grow

fn grow(&mut self, n: uint, initval: &T)

Method grow_set

fn grow_set(&mut self, index: uint, initval: &T, val: T)

Trait OwnedEqVector

Method dedup

fn dedup(&mut self)

Trait OwnedVector

Method move_iter

fn move_iter(self) -> MoveIterator<T>

Method move_rev_iter

fn move_rev_iter(self) -> MoveRevIterator<T>

Method reserve

fn reserve(&mut self, n: uint)

Method reserve_at_least

fn reserve_at_least(&mut self, n: uint)

Method capacity

fn capacity(&self) -> uint

Method shrink_to_fit

fn shrink_to_fit(&mut self)

Method push

fn push(&mut self, t: T)

Method push_all_move

fn push_all_move(&mut self, rhs: ~[T])

Method pop

fn pop(&mut self) -> T

Method pop_opt

fn pop_opt(&mut self) -> Option<T>

Method shift

fn shift(&mut self) -> T

Method shift_opt

fn shift_opt(&mut self) -> Option<T>

Method unshift

fn unshift(&mut self, x: T)

Method insert

fn insert(&mut self, i: uint, x: T)

Method remove

fn remove(&mut self, i: uint) -> T

Method swap_remove

fn swap_remove(&mut self, index: uint) -> T

Method truncate

fn truncate(&mut self, newlen: uint)

Method retain

fn retain(&mut self, f: &fn(t: &T) -> bool)

Method partition

fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T])

Method grow_fn

fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T)

Trait Vector

Any vector that can be represented as a slice.

Method as_slice

fn as_slice<'a>(&'a self) -> &'a [T]

Work with self as a slice.

Trait VectorVector

Method concat_vec

fn concat_vec(&self) -> ~[T]

Method connect_vec

fn connect_vec(&self, sep: &T) -> ~[T]

Implementation of Iterator<&'self [T]> for SplitIterator<'self, T> where <'self, T>

Method next

fn next(&mut self) -> Option<&'self [T]>

Method size_hint

fn size_hint(&self) -> (uint, Option<uint>)

Implementation of Iterator<&'self [T]> for RSplitIterator<'self, T> where <'self, T>

Method next

fn next(&mut self) -> Option<&'self [T]>

Method size_hint

fn size_hint(&self) -> (uint, Option<uint>)

Implementation of VectorVector<T> for &'self [~[T]] where <'self, T: Clone>

Method concat_vec

fn concat_vec(&self) -> ~[T]

Flattens a vector of slices of T into a single vector of T.

Method connect_vec

fn connect_vec(&self, sep: &T) -> ~[T]

Concatenate a vector of vectors, placing a given separator between each.

Implementation of VectorVector<T> for &'self [&'self [T]] where <'self, T: Clone>

Method concat_vec

fn concat_vec(&self) -> ~[T]

Flattens a vector of slices of T into a single vector of T.

Method connect_vec

fn connect_vec(&self, sep: &T) -> ~[T]

Concatenate a vector of slices, placing a given separator between each.

Implementation of ::std::clone::Clone for WindowIter<'self, T> where <'self, T: ::std::clone::Clone>

Automatically derived.

Method clone

fn clone(&self) -> WindowIter<'self, T>

Implementation of Iterator<&'self [T]> for WindowIter<'self, T> where <'self, T>

Method next

fn next(&mut self) -> Option<&'self [T]>

Method size_hint

fn size_hint(&self) -> (uint, Option<uint>)

Implementation of ::std::clone::Clone for ChunkIter<'self, T> where <'self, T: ::std::clone::Clone>

Automatically derived.

Method clone

fn clone(&self) -> ChunkIter<'self, T>

Implementation of Iterator<&'self [T]> for ChunkIter<'self, T> where <'self, T>

Method next

fn next(&mut self) -> Option<&'self [T]>

Method size_hint

fn size_hint(&self) -> (uint, Option<uint>)

Implementation of DoubleEndedIterator<&'self [T]> for ChunkIter<'self, T> where <'self, T>

Method next_back

fn next_back(&mut self) -> Option<&'self [T]>

Implementation of RandomAccessIterator<&'self [T]> for ChunkIter<'self, T> where <'self, T>

Method indexable

fn indexable(&self) -> uint

Method idx

fn idx(&self, index: uint) -> Option<&'self [T]>

Implementation of Vector<T> for &'self [T] where <'self, T>

Method as_slice

fn as_slice<'a>(&'a self) -> &'a [T]

Implementation of Vector<T> for ~[T] where <T>

Method as_slice

fn as_slice<'a>(&'a self) -> &'a [T]

Implementation of Vector<T> for @[T] where <T>

Method as_slice

fn as_slice<'a>(&'a self) -> &'a [T]

Implementation of Container for &'self [T] where <'self, T>

Method len

fn len(&self) -> uint

Returns the length of a vector

Implementation of Container for ~[T] where <T>

Method len

fn len(&self) -> uint

Returns the length of a vector

Implementation of CopyableVector<T> for &'self [T] where <'self, T: Clone>

Extension methods for vector slices

Method to_owned

fn to_owned(&self) -> ~[T]

Returns a copy of v.

Method into_owned

fn into_owned(self) -> ~[T]

Implementation of CopyableVector<T> for ~[T] where <T: Clone>

Extension methods for owned vectors

Method to_owned

fn to_owned(&self) -> ~[T]

Method into_owned

fn into_owned(self) -> ~[T]

Implementation of CopyableVector<T> for @[T] where <T: Clone>

Extension methods for managed vectors

Method to_owned

fn to_owned(&self) -> ~[T]

Method into_owned

fn into_owned(self) -> ~[T]

Implementation of ImmutableVector<'self, T> for &'self [T] where <'self, T>

Extension methods for vectors

Method slice

fn slice(&self, start: uint, end: uint) -> &'self [T]

Returns a slice of self between start and end.

Fails when start or end point outside the bounds of self, or when start > end.

Method slice_from

fn slice_from(&self, start: uint) -> &'self [T]

Returns a slice of self from start to the end of the vec.

Fails when start points outside the bounds of self.

Method slice_to

fn slice_to(&self, end: uint) -> &'self [T]

Returns a slice of self from the start of the vec to end.

Fails when end points outside the bounds of self.

Method iter

fn iter(self) -> VecIterator<'self, T>

Method rev_iter

fn rev_iter(self) -> RevIterator<'self, T>

Method split_iter

fn split_iter(self, pred: &'self fn(&T) -> bool) -> SplitIterator<'self, T>

Returns an iterator over the subslices of the vector which are separated by elements that match pred.

Method splitn_iter

fn splitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) ->
 SplitIterator<'self, T>

Returns an iterator over the subslices of the vector which are separated by elements that match pred, limited to splitting at most n times.

Method rsplit_iter

fn rsplit_iter(self, pred: &'self fn(&T) -> bool) -> RSplitIterator<'self, T>

Returns an iterator over the subslices of the vector which are separated by elements that match pred. This starts at the end of the vector and works backwards.

Method rsplitn_iter

fn rsplitn_iter(self, n: uint, pred: &'self fn(&T) -> bool) ->
 RSplitIterator<'self, T>

Returns an iterator over the subslices of the vector which are separated by elements that match pred limited to splitting at most n times. This starts at the end of the vector and works backwards.

Method window_iter

fn window_iter(self, size: uint) -> WindowIter<'self, T>

Returns an iterator over all contiguous windows of length size. The windows overlap. If the vector is shorter than size, the iterator returns no values.

Failure

Fails if size is 0.

Example

Print the adjacent pairs of a vector (i.e. [1,2], [2,3], [3,4]):

let v = &[1,2,3,4];
for win in v.window_iter() {
    printfln!(win);
}

Method chunk_iter

fn chunk_iter(self, size: uint) -> ChunkIter<'self, T>

Returns an iterator over size elements of the vector at a time. The chunks do not overlap. If size does not divide the length of the vector, then the last chunk will not have length size.

Failure

Fails if size is 0.

Example

Print the vector two elements at a time (i.e. [1,2], [3,4], [5]):

let v = &[1,2,3,4,5];
for win in v.chunk_iter() {
    printfln!(win);
}

Method head

fn head(&self) -> &'self T

Returns the first element of a vector, failing if the vector is empty.

Method head_opt

fn head_opt(&self) -> Option<&'self T>

Returns the first element of a vector, or None if it is empty

Method tail

fn tail(&self) -> &'self [T]

Returns all but the first element of a vector

Method tailn

fn tailn(&self, n: uint) -> &'self [T]

Returns all but the first `n' elements of a vector

Method init

fn init(&self) -> &'self [T]

Returns all but the last element of a vector

Method initn

fn initn(&self, n: uint) -> &'self [T]

Returns all but the last `n' elemnts of a vector

Method last

fn last(&self) -> &'self T

Returns the last element of a vector, failing if the vector is empty.

Method last_opt

fn last_opt(&self) -> Option<&'self T>

Returns the last element of a vector, or None if it is empty.

Method flat_map

fn flat_map<U>(&self, f: &fn(t: &T) -> ~[U]) -> ~[U]

Apply a function to each element of a vector and return a concatenation of each result vector

Method unsafe_ref

unsafe fn unsafe_ref(&self, index: uint) -> *T

Returns a pointer to the element at the given index, without doing bounds checking.

Method bsearch

fn bsearch(&self, f: &fn(&T) -> Ordering) -> Option<uint>

Binary search a sorted vector with a comparator function.

The comparator should implement an order consistent with the sort order of the underlying vector, returning an order code that indicates whether its argument is Less, Equal or Greater the desired target.

Returns the index where the comparator returned Equal, or None if not found.

Method map

fn map<U>(&self, f: &fn(t: &T) -> U) -> ~[U]

Deprecated, use iterators where possible (self.iter().map(f)). Apply a function to each element of a vector and return the results.

Method as_imm_buf

fn as_imm_buf<U>(&self, f: &fn(*T, uint) -> U) -> U

Work with the buffer of a vector.

Allows for unsafe manipulation of vector contents, which is useful for foreign interop.

Implementation of ImmutableEqVector<T> for &'self [T] where <'self, T: Eq>

Method position_elem

fn position_elem(&self, x: &T) -> Option<uint>

Find the first index containing a matching value

Method rposition_elem

fn rposition_elem(&self, t: &T) -> Option<uint>

Find the last index containing a matching value

Method contains

fn contains(&self, x: &T) -> bool

Return true if a vector contains an element with the given value

Implementation of ImmutableTotalOrdVector<T> for &'self [T] where <'self, T: TotalOrd>

Method bsearch_elem

fn bsearch_elem(&self, x: &T) -> Option<uint>

Binary search a sorted vector for a given element.

Returns the index of the element or None if not found.

Implementation of ImmutableCopyableVector<T> for &'self [T] where <'self, T: Clone>

Extension methods for vectors

Method partitioned

fn partitioned(&self, f: &fn(&T) -> bool) -> (~[T], ~[T])

Partitions the vector into those that satisfies the predicate, and those that do not.

Method unsafe_get

unsafe fn unsafe_get(&self, index: uint) -> T

Returns the element at the given index, without doing bounds checking.

Implementation of OwnedVector<T> for ~[T] where <T>

Method move_iter

fn move_iter(self) -> MoveIterator<T>

Creates a consuming iterator, that is, one that moves each value out of the vector (from start to end). The vector cannot be used after calling this.

Note that this performs O(n) swaps, and so move_rev_iter (which just calls pop repeatedly) is more efficient.

Examples

let v = ~[~"a", ~"b"];
for s in v.move_iter() {
  // s has type ~str, not &~str
  println(s);
}

Method move_rev_iter

fn move_rev_iter(self) -> MoveRevIterator<T>

Creates a consuming iterator that moves out of the vector in reverse order. Also see move_iter, however note that this is more efficient.

Method reserve

fn reserve(&mut self, n: uint)

Reserves capacity for exactly n elements in the given vector.

If the capacity for self is already equal to or greater than the requested capacity, then no action is taken.

Arguments

  • n - The number of elements to reserve space for

Method reserve_at_least

fn reserve_at_least(&mut self, n: uint)

Reserves capacity for at least n elements in the given vector.

This function will over-allocate in order to amortize the allocation costs in scenarios where the caller may need to repeatedly reserve additional space.

If the capacity for self is already equal to or greater than the requested capacity, then no action is taken.

Arguments

  • n - The number of elements to reserve space for

Method capacity

fn capacity(&self) -> uint

Returns the number of elements the vector can hold without reallocating.

Method shrink_to_fit

fn shrink_to_fit(&mut self)

Shrink the capacity of the vector to match the length

Method push

fn push(&mut self, t: T)

Append an element to a vector

Method push_all_move

fn push_all_move(&mut self, mut rhs: ~[T])

Takes ownership of the vector rhs, moving all elements into the current vector. This does not copy any elements, and it is illegal to use the rhs vector after calling this method (because it is moved here).

Example

let mut a = ~[~1];
a.push_all_move(~[~2, ~3, ~4]);
assert!(a == ~[~1, ~2, ~3, ~4]);

Method pop_opt

fn pop_opt(&mut self) -> Option<T>

Remove the last element from a vector and return it, or None if it is empty

Method pop

fn pop(&mut self) -> T

Remove the last element from a vector and return it, failing if it is empty

Method shift

fn shift(&mut self) -> T

Removes the first element from a vector and return it

Method shift_opt

fn shift_opt(&mut self) -> Option<T>

Removes the first element from a vector and return it, or None if it is empty

Method unshift

fn unshift(&mut self, x: T)

Prepend an element to the vector

Method insert

fn insert(&mut self, i: uint, x: T)

Insert an element at position i within v, shifting all elements after position i one position to the right.

Method remove

fn remove(&mut self, i: uint) -> T

Remove and return the element at position i within v, shifting all elements after position i one position to the left.

Method swap_remove

fn swap_remove(&mut self, index: uint) -> T

Remove an element from anywhere in the vector and return it, replacing it with the last element. This does not preserve ordering, but is O(1).

Fails if index >= length.

Method truncate

fn truncate(&mut self, newlen: uint)

Shorten a vector, dropping excess elements.

Method retain

fn retain(&mut self, f: &fn(t: &T) -> bool)

Like filter(), but in place. Preserves order of v. Linear time.

Method partition

fn partition(self, f: &fn(&T) -> bool) -> (~[T], ~[T])

Partitions the vector into those that satisfies the predicate, and those that do not.

Method grow_fn

fn grow_fn(&mut self, n: uint, op: &fn(uint) -> T)

Expands a vector in place, initializing the new elements to the result of a function

Function init_op is called n times with the values [0..n)

Arguments

  • n - The number of elements to add
  • init_op - A function to call to retreive each appended element's value

Implementation of Mutable for ~[T] where <T>

Method clear

fn clear(&mut self)

Clear the vector, removing all values.

Implementation of OwnedCopyableVector<T> for ~[T] where <T: Clone>

Method push_all

fn push_all(&mut self, rhs: &[T])

Iterates over the slice rhs, copies each element, and then appends it to the vector provided v. The rhs vector is traversed in-order.

Example

let mut a = ~[1];
a.push_all([2, 3, 4]);
assert!(a == ~[1, 2, 3, 4]);

Method grow

fn grow(&mut self, n: uint, initval: &T)

Expands a vector in place, initializing the new elements to a given value

Arguments

  • n - The number of elements to add
  • initval - The value for the new elements

Method grow_set

fn grow_set(&mut self, index: uint, initval: &T, val: T)

Sets the value of a vector element at a given index, growing the vector as needed

Sets the element at position index to val. If index is past the end of the vector, expands the vector by replicating initval to fill the intervening space.

Implementation of OwnedEqVector<T> for ~[T] where <T: Eq>

Method dedup

fn dedup(&mut self)

Remove consecutive repeated elements from a vector; if the vector is sorted, this removes all duplicates.

Implementation of MutableVector<'self, T> for &'self mut [T] where <'self, T>

Method mut_slice

fn mut_slice(self, start: uint, end: uint) -> &'self mut [T]

Return a slice that points into another slice.

Method mut_slice_from

fn mut_slice_from(self, start: uint) -> &'self mut [T]

Returns a slice of self from start to the end of the vec.

Fails when start points outside the bounds of self.

Method mut_slice_to

fn mut_slice_to(self, end: uint) -> &'self mut [T]

Returns a slice of self from the start of the vec to end.

Fails when end points outside the bounds of self.

Method mut_split

fn mut_split(self, mid: uint) -> (&'self mut [T], &'self mut [T])

Method mut_iter

fn mut_iter(self) -> VecMutIterator<'self, T>

Method mut_rev_iter

fn mut_rev_iter(self) -> MutRevIterator<'self, T>

Method swap

fn swap(self, a: uint, b: uint)

Swaps two elements in a vector

Arguments

  • a - The index of the first element
  • b - The index of the second element

Method reverse

fn reverse(self)

Reverse the order of elements in a vector, in place

Method move_from

fn move_from(self, mut src: ~[T], start: uint, end: uint) -> uint

Method unsafe_mut_ref

unsafe fn unsafe_mut_ref(self, index: uint) -> *mut T

Method unsafe_set

unsafe fn unsafe_set(self, index: uint, val: T)

Method as_mut_buf

fn as_mut_buf<U>(self, f: &fn(*mut T, uint) -> U) -> U

Similar to as_imm_buf but passing a *mut T

Implementation of MutableCloneableVector<T> for &'self mut [T] where <'self, T: Clone>

Method copy_from

fn copy_from(self, src: &[T]) -> uint

Implementation of Clone for ~[A] where <A: Clone>

Method clone

fn clone(&self) -> ~[A]

Implementation of DeepClone for ~[A] where <A: DeepClone>

Method deep_clone

fn deep_clone(&self) -> ~[A]

Implementation of Zero for &'self [A] where <'self, A>

Method zero

fn zero() -> &'self [A]

Method is_zero

fn is_zero(&self) -> bool

Implementation of Zero for ~[A] where <A>

Method zero

fn zero() -> ~[A]

Method is_zero

fn is_zero(&self) -> bool

Implementation of Zero for @[A] where <A>

Method zero

fn zero() -> @[A]

Method is_zero

fn is_zero(&self) -> bool

Implementation of RandomAccessIterator<&'self T> for VecIterator<'self, T> where <'self, T>

Method indexable

fn indexable(&self) -> uint

Method idx

fn idx(&self, index: uint) -> Option<&'self T>

Implementation of Iterator<&'self T> for VecIterator<'self, T> where <'self, T>

Method next

fn next(&mut self) -> Option<&'self T>

Method size_hint

fn size_hint(&self) -> (uint, Option<uint>)

Implementation of DoubleEndedIterator<&'self T> for VecIterator<'self, T> where <'self, T>

Method next_back

fn next_back(&mut self) -> Option<&'self T>

Implementation of ExactSize<&'self T> for VecIterator<'self, T> where <'self, T>

Implementation of ExactSize<&'self mut T> for VecMutIterator<'self, T> where <'self, T>

Implementation of Clone for VecIterator<'self, T> where <'self, T>

Method clone

fn clone(&self) -> VecIterator<'self, T>

Implementation of Iterator<&'self mut T> for VecMutIterator<'self, T> where <'self, T>

Method next

fn next(&mut self) -> Option<&'self mut T>

Method size_hint

fn size_hint(&self) -> (uint, Option<uint>)

Implementation of DoubleEndedIterator<&'self mut T> for VecMutIterator<'self, T> where <'self, T>

Method next_back

fn next_back(&mut self) -> Option<&'self mut T>

Implementation of ::std::clone::Clone for MoveIterator<T> where <T: ::std::clone::Clone>

Automatically derived.

Method clone

fn clone(&self) -> MoveIterator<T>

Implementation of Iterator<T> for MoveIterator<T> where <T>

Method next

fn next(&mut self) -> Option<T>

Method size_hint

fn size_hint(&self) -> (uint, Option<uint>)

Implementation of ::std::clone::Clone for MoveRevIterator<T> where <T: ::std::clone::Clone>

Automatically derived.

Method clone

fn clone(&self) -> MoveRevIterator<T>

Implementation of Iterator<T> for MoveRevIterator<T> where <T>

Method next

fn next(&mut self) -> Option<T>

Method size_hint

fn size_hint(&self) -> (uint, Option<uint>)

Implementation of FromIterator<A> for ~[A] where <A>

Method from_iterator

fn from_iterator<T: Iterator<A>>(iterator: &mut T) -> ~[A]

Implementation of Extendable<A> for ~[A] where <A>

Method extend

fn extend<T: Iterator<A>>(&mut self, iterator: &mut T)

Function append

fn append<T: Clone>(lhs: ~[T], rhs: &[T]) -> ~[T]

Iterates over the rhs vector, copying each element and appending it to the lhs. Afterwards, the lhs is then returned for use again.

Function append_one

fn append_one<T>(lhs: ~[T], x: T) -> ~[T]

Appends one element to the vector provided. The vector itself is then returned for use again.

Function build

fn build<A>(builder: &fn(push: &fn(v: A))) -> ~[A]

Builds a vector by calling a provided function with an argument function that pushes an element to the back of a vector.

Arguments

Function build_sized

fn build_sized<A>(size: uint, builder: &fn(push: &fn(v: A))) -> ~[A]

Builds a vector by calling a provided function with an argument function that pushes an element to the back of a vector. This version takes an initial capacity for the vector.

Arguments

Function build_sized_opt

fn build_sized_opt<A>(size: Option<uint>, builder: &fn(push: &fn(v: A))) ->
 ~[A]

Builds a vector by calling a provided function with an argument function that pushes an element to the back of a vector. This version takes an initial size for the vector.

Arguments

Function concat

fn concat<T: Clone>(v: &[~[T]]) -> ~[T]

Flattens a vector of vectors of T into a single vector of T.

Function concat_slices

fn concat_slices<T: Clone>(v: &[&[T]]) -> ~[T]

Flattens a vector of vectors of T into a single vector of T.

Function connect

fn connect<T: Clone>(v: &[~[T]], sep: &T) -> ~[T]

Concatenate a vector of vectors, placing a given separator between each

Function connect_slices

fn connect_slices<T: Clone>(v: &[&[T]], sep: &T) -> ~[T]

Concatenate a vector of vectors, placing a given separator between each

Function each_permutation

fn each_permutation<T: Clone>(values: &[T], fun: &fn(perm: &[T]) -> bool) ->
 bool

Iterate over all permutations of vector v.

Permutations are produced in lexicographic order with respect to the order of elements in v (so if v is sorted then the permutations are lexicographically sorted).

The total number of permutations produced is v.len()!. If v contains repeated elements, then some permutations are repeated.

See Algorithms to generate permutations.

# Arguments

Function flat_map

fn flat_map<T, U>(v: &[T], f: &fn(t: &T) -> ~[U]) -> ~[U]

Apply a function to each element of a vector and return a concatenation of each result vector

Function from_buf

unsafe fn from_buf<T>(ptr: *T, elts: uint) -> ~[T]

Constructs a vector from an unsafe pointer to a buffer

Arguments

Function from_elem

fn from_elem<T: Clone>(n_elts: uint, t: T) -> ~[T]

Creates and initializes an owned vector.

Creates an owned vector of size n_elts and initializes the elements to the value t.

Function from_fn

fn from_fn<T>(n_elts: uint, op: &fn(uint) -> T) -> ~[T]

Creates and initializes an owned vector.

Creates an owned vector of size n_elts and initializes the elements to the value returned by the function op.

Function same_length

fn same_length<T, U>(xs: &[T], ys: &[U]) -> bool

Returns true if two vectors have the same length

Function unzip

fn unzip<T, U>(v: ~[(T, U)]) -> (~[T], ~[U])

Convert a vector of pairs into a pair of vectors.

Returns a tuple containing two vectors where the i-th element of the first vector contains the first element of the i-th tuple of the input vector, and the i-th element of the second vector contains the second element of the i-th tuple of the input vector.

Function unzip_slice

fn unzip_slice<T: Clone, U: Clone>(v: &[(T, U)]) -> (~[T], ~[U])

Convert a vector of pairs into a pair of vectors, by reference. As unzip().

Function with_capacity

fn with_capacity<T>(capacity: uint) -> ~[T]

Creates a new vector with a capacity of capacity