Module collections::vec
[−]
[src]
A growable list type with heap-allocated contents, written Vec<T> but
pronounced 'vector.'
Vectors have O(1) indexing, amortized O(1) push (to the end) and
O(1) pop (from the end).
Examples
You can explicitly create a Vec<T> with new():
let v: Vec<i32> = Vec::new();
...or by using the vec! macro:
let v: Vec<i32> = vec![]; let v = vec![1, 2, 3, 4, 5]; let v = vec![0; 10]; // ten zeroes
You can push values onto the end of a vector (which will grow the vector
as needed):
let mut v = vec![1, 2]; v.push(3);
Popping values works in much the same way:
fn main() { let mut v = vec![1, 2]; let two = v.pop(); }let mut v = vec![1, 2]; let two = v.pop();
Vectors also support indexing (through the Index and IndexMut traits):
let mut v = vec![1, 2, 3]; let three = v[2]; v[1] = v[1] + 5;
Reexports
use core::prelude::v1::*; |
use alloc::raw_vec::RawVec; |
use alloc::boxed::Box; |
use alloc::heap::EMPTY; |
use core::cmp::Ordering; |
use core::fmt; |
use core::hash::{self, Hash}; |
use core::intrinsics::{arith_offset, assume, needs_drop}; |
use core::iter::FromIterator; |
use core::mem; |
use core::ops::{Index, IndexMut}; |
use core::ops; |
use core::ptr; |
use core::slice; |
use borrow::{Cow, IntoCow}; |
use super::range::RangeArgument; |
Structs
| Drain |
A draining iterator for |
| IntoIter |
An iterator that moves out of a vector. |
| Vec |
A growable list type, written |
Functions
| from_elem |