doc: Normalize example style
Remove unnecessary `use std::vec::Vec`. Use ``` code blocks with rust as default instead of spelling it out.
This commit is contained in:
parent
eafcf6ba41
commit
8d54ec8f4b
@ -35,8 +35,7 @@
|
||||
///
|
||||
/// # Examples
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::vec::Vec;
|
||||
/// ```
|
||||
/// let mut vec = Vec::new();
|
||||
/// vec.push(1i);
|
||||
/// vec.push(2i);
|
||||
@ -60,7 +59,7 @@
|
||||
///
|
||||
/// The `vec!` macro is provided to make initialization more convenient:
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2i, 3i];
|
||||
/// vec.push(4);
|
||||
/// assert_eq!(vec, vec![1, 2, 3, 4]);
|
||||
@ -115,8 +114,7 @@ impl<T> Vec<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::vec::Vec;
|
||||
/// ```
|
||||
/// let mut vec: Vec<int> = Vec::new();
|
||||
/// ```
|
||||
#[inline]
|
||||
@ -141,8 +139,7 @@ pub fn new() -> Vec<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::vec::Vec;
|
||||
/// ```
|
||||
/// let mut vec: Vec<int> = Vec::with_capacity(10);
|
||||
///
|
||||
/// // The vector contains no items, even though it has capacity for more
|
||||
@ -177,8 +174,7 @@ pub fn with_capacity(capacity: uint) -> Vec<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::vec::Vec;
|
||||
/// ```
|
||||
/// let vec = Vec::from_fn(3, |idx| idx * 2);
|
||||
/// assert_eq!(vec, vec![0, 2, 4]);
|
||||
/// ```
|
||||
@ -248,7 +244,7 @@ pub unsafe fn from_raw_parts(length: uint, capacity: uint,
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let vec = vec![1i, 2i, 3i, 4i];
|
||||
/// let (even, odd) = vec.partition(|&n| n % 2 == 0);
|
||||
/// assert_eq!(even, vec![2, 4]);
|
||||
@ -277,7 +273,7 @@ impl<T: Clone> Vec<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let vec = vec![1i, 2i];
|
||||
/// let vec = vec.append([3i, 4i]);
|
||||
/// assert_eq!(vec, vec![1, 2, 3, 4]);
|
||||
@ -292,8 +288,7 @@ pub fn append(mut self, second: &[T]) -> Vec<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::vec::Vec;
|
||||
/// ```
|
||||
/// let slice = [1i, 2, 3];
|
||||
/// let vec = Vec::from_slice(slice);
|
||||
/// ```
|
||||
@ -309,8 +304,7 @@ pub fn from_slice(values: &[T]) -> Vec<T> {
|
||||
/// Creates a `Vec` with `length` copies of `value`.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// # use std::vec::Vec;
|
||||
/// ```
|
||||
/// let vec = Vec::from_elem(3, "hi");
|
||||
/// println!("{}", vec); // prints [hi, hi, hi]
|
||||
/// ```
|
||||
@ -335,7 +329,7 @@ pub fn from_elem(length: uint, value: T) -> Vec<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i];
|
||||
/// vec.push_all([2i, 3, 4]);
|
||||
/// assert_eq!(vec, vec![1, 2, 3, 4]);
|
||||
@ -365,7 +359,7 @@ pub fn push_all(&mut self, other: &[T]) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec!["hello"];
|
||||
/// vec.grow(2, &("world"));
|
||||
/// assert_eq!(vec, vec!["hello", "world", "world"]);
|
||||
@ -389,7 +383,7 @@ pub fn grow(&mut self, n: uint, value: &T) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec!["a", "b", "c"];
|
||||
/// vec.grow_set(1, &("fill"), "d");
|
||||
/// vec.grow_set(4, &("fill"), "e");
|
||||
@ -411,7 +405,7 @@ pub fn grow_set(&mut self, index: uint, initval: &T, value: T) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let vec = vec![1i, 2, 3, 4];
|
||||
/// let (even, odd) = vec.partitioned(|&n| n % 2 == 0);
|
||||
/// assert_eq!(even, vec![2i, 4]);
|
||||
@ -561,8 +555,7 @@ impl<T> Vec<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::vec::Vec;
|
||||
/// ```
|
||||
/// let vec: Vec<int> = Vec::with_capacity(10);
|
||||
/// assert_eq!(vec.capacity(), 10);
|
||||
/// ```
|
||||
@ -580,8 +573,7 @@ pub fn capacity(&self) -> uint {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::vec::Vec;
|
||||
/// ```
|
||||
/// let mut vec: Vec<int> = vec![1i];
|
||||
/// vec.reserve_additional(10);
|
||||
/// assert!(vec.capacity() >= 11);
|
||||
@ -606,7 +598,7 @@ pub fn reserve_additional(&mut self, extra: uint) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3];
|
||||
/// vec.reserve(10);
|
||||
/// assert!(vec.capacity() >= 10);
|
||||
@ -624,8 +616,7 @@ pub fn reserve(&mut self, capacity: uint) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// # use std::vec::Vec;
|
||||
/// ```
|
||||
/// let mut vec: Vec<int> = Vec::with_capacity(10);
|
||||
/// vec.reserve_exact(11);
|
||||
/// assert_eq!(vec.capacity(), 11);
|
||||
@ -648,7 +639,7 @@ pub fn reserve_exact(&mut self, capacity: uint) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3];
|
||||
/// vec.shrink_to_fit();
|
||||
/// ```
|
||||
@ -680,7 +671,7 @@ pub fn shrink_to_fit(&mut self) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3];
|
||||
/// assert_eq!(vec.pop(), Some(3));
|
||||
/// assert_eq!(vec, vec![1, 2]);
|
||||
@ -705,7 +696,7 @@ pub fn pop(&mut self) -> Option<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2];
|
||||
/// vec.push(3);
|
||||
/// assert_eq!(vec, vec![1, 2, 3]);
|
||||
@ -741,7 +732,7 @@ pub fn push(&mut self, value: T) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let vec = vec![1i, 2];
|
||||
/// let vec = vec.append_one(3);
|
||||
/// assert_eq!(vec, vec![1, 2, 3]);
|
||||
@ -759,7 +750,7 @@ pub fn append_one(mut self, x: T) -> Vec<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3, 4];
|
||||
/// vec.truncate(2);
|
||||
/// assert_eq!(vec, vec![1, 2]);
|
||||
@ -780,7 +771,7 @@ pub fn truncate(&mut self, len: uint) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// fn foo(slice: &mut [int]) {}
|
||||
///
|
||||
/// let mut vec = vec![1i, 2];
|
||||
@ -802,7 +793,7 @@ pub fn as_mut_slice<'a>(&'a mut self) -> &'a mut [T] {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let v = vec!["a".to_string(), "b".to_string()];
|
||||
/// for s in v.move_iter() {
|
||||
/// // s has type String, not &String
|
||||
@ -848,7 +839,7 @@ pub unsafe fn set_len(&mut self, len: uint) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// #![allow(deprecated)]
|
||||
///
|
||||
/// let vec = vec![1i, 2, 3];
|
||||
@ -868,7 +859,7 @@ pub fn get<'a>(&'a self, index: uint) -> &'a T {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3];
|
||||
/// *vec.get_mut(1) = 4;
|
||||
/// assert_eq!(vec, vec![1i, 4, 3]);
|
||||
@ -883,7 +874,7 @@ pub fn get_mut<'a>(&'a mut self, index: uint) -> &'a mut T {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let vec = vec![1i, 2, 3];
|
||||
/// for num in vec.iter() {
|
||||
/// println!("{}", *num);
|
||||
@ -900,7 +891,7 @@ pub fn iter<'a>(&'a self) -> Items<'a,T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3];
|
||||
/// for num in vec.mut_iter() {
|
||||
/// *num = 0;
|
||||
@ -918,7 +909,7 @@ pub fn mut_iter<'a>(&'a mut self) -> MutItems<'a,T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut v = vec![5i, 4, 1, 3, 2];
|
||||
/// v.sort_by(|a, b| a.cmp(b));
|
||||
/// assert_eq!(v, vec![1i, 2, 3, 4, 5]);
|
||||
@ -941,7 +932,7 @@ pub fn sort_by(&mut self, compare: |&T, &T| -> Ordering) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let vec = vec![1i, 2, 3, 4];
|
||||
/// assert!(vec.slice(0, 2) == [1, 2]);
|
||||
/// ```
|
||||
@ -958,7 +949,7 @@ pub fn slice<'a>(&'a self, start: uint, end: uint) -> &'a [T] {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let vec = vec![1i, 2, 3];
|
||||
/// assert!(vec.tail() == [2, 3]);
|
||||
/// ```
|
||||
@ -975,7 +966,7 @@ pub fn tail<'a>(&'a self) -> &'a [T] {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let vec = vec![1i, 2, 3, 4];
|
||||
/// assert!(vec.tailn(2) == [3, 4]);
|
||||
/// ```
|
||||
@ -989,7 +980,7 @@ pub fn tailn<'a>(&'a self, n: uint) -> &'a [T] {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let vec = vec![1i, 2, 3];
|
||||
/// assert!(vec.last() == Some(&3));
|
||||
/// ```
|
||||
@ -1003,7 +994,7 @@ pub fn last<'a>(&'a self) -> Option<&'a T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3];
|
||||
/// *vec.mut_last().unwrap() = 4;
|
||||
/// assert_eq!(vec, vec![1i, 2, 4]);
|
||||
@ -1019,7 +1010,7 @@ pub fn mut_last<'a>(&'a mut self) -> Option<&'a mut T> {
|
||||
/// Returns `None` if `index` is out of bounds.
|
||||
///
|
||||
/// # Example
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut v = vec!["foo".to_string(), "bar".to_string(),
|
||||
/// "baz".to_string(), "qux".to_string()];
|
||||
///
|
||||
@ -1051,7 +1042,7 @@ pub fn swap_remove(&mut self, index: uint) -> Option<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3];
|
||||
/// vec.unshift(4);
|
||||
/// assert_eq!(vec, vec![4, 1, 2, 3]);
|
||||
@ -1071,7 +1062,7 @@ pub fn unshift(&mut self, element: T) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3];
|
||||
/// assert!(vec.shift() == Some(1));
|
||||
/// assert_eq!(vec, vec![2, 3]);
|
||||
@ -1091,7 +1082,7 @@ pub fn shift(&mut self) -> Option<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3];
|
||||
/// vec.insert(1, 4);
|
||||
/// assert_eq!(vec, vec![1, 4, 2, 3]);
|
||||
@ -1125,7 +1116,7 @@ pub fn insert(&mut self, index: uint, element: T) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut v = vec![1i, 2, 3];
|
||||
/// assert_eq!(v.remove(1), Some(2));
|
||||
/// assert_eq!(v, vec![1, 3]);
|
||||
@ -1164,7 +1155,7 @@ pub fn remove(&mut self, index: uint) -> Option<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![box 1i];
|
||||
/// vec.push_all_move(vec![box 2, box 3, box 4]);
|
||||
/// assert_eq!(vec, vec![box 1, box 2, box 3, box 4]);
|
||||
@ -1183,7 +1174,7 @@ pub fn push_all_move(&mut self, other: Vec<T>) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3, 4];
|
||||
/// assert!(vec.mut_slice(0, 2) == [1, 2]);
|
||||
/// ```
|
||||
@ -1201,7 +1192,7 @@ pub fn mut_slice<'a>(&'a mut self, start: uint, end: uint)
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3, 4];
|
||||
/// assert!(vec.mut_slice_from(2) == [3, 4]);
|
||||
/// ```
|
||||
@ -1218,7 +1209,7 @@ pub fn mut_slice_from<'a>(&'a mut self, start: uint) -> &'a mut [T] {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3, 4];
|
||||
/// assert!(vec.mut_slice_to(2) == [1, 2]);
|
||||
/// ```
|
||||
@ -1239,7 +1230,7 @@ pub fn mut_slice_to<'a>(&'a mut self, end: uint) -> &'a mut [T] {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3, 4, 5, 6];
|
||||
///
|
||||
/// // scoped to restrict the lifetime of the borrows
|
||||
@ -1270,7 +1261,7 @@ pub fn mut_split_at<'a>(&'a mut self, mid: uint) -> (&'a mut [T], &'a mut [T]) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut v = vec![1i, 2, 3];
|
||||
/// v.reverse();
|
||||
/// assert_eq!(v, vec![3i, 2, 1]);
|
||||
@ -1288,7 +1279,7 @@ pub fn reverse(&mut self) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let vec = vec![1i, 2, 3];
|
||||
/// assert!(vec.slice_from(1) == [2, 3]);
|
||||
/// ```
|
||||
@ -1305,7 +1296,7 @@ pub fn slice_from<'a>(&'a self, start: uint) -> &'a [T] {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let vec = vec![1i, 2, 3, 4];
|
||||
/// assert!(vec.slice_to(2) == [1, 2]);
|
||||
/// ```
|
||||
@ -1390,7 +1381,7 @@ pub fn as_mut_ptr(&mut self) -> *mut T {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 3, 4];
|
||||
/// vec.retain(|x| x%2 == 0);
|
||||
/// assert_eq!(vec, vec![2, 4]);
|
||||
@ -1421,7 +1412,7 @@ pub fn retain(&mut self, f: |&T| -> bool) {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![0u, 1];
|
||||
/// vec.grow_fn(3, |i| i);
|
||||
/// assert_eq!(vec, vec![0, 1, 0, 1, 2]);
|
||||
@ -1442,7 +1433,7 @@ impl<T:Ord> Vec<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![3i, 1, 2];
|
||||
/// vec.sort();
|
||||
/// assert_eq!(vec, vec![1, 2, 3]);
|
||||
@ -1464,7 +1455,7 @@ impl<T:PartialEq> Vec<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let vec = vec![1i, 2, 3];
|
||||
/// assert!(vec.contains(&1));
|
||||
/// ```
|
||||
@ -1479,7 +1470,7 @@ pub fn contains(&self, x: &T) -> bool {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// let mut vec = vec![1i, 2, 2, 3, 2];
|
||||
/// vec.dedup();
|
||||
/// assert_eq!(vec, vec![1i, 2, 3, 2]);
|
||||
@ -1574,7 +1565,7 @@ impl<T> Vector<T> for Vec<T> {
|
||||
///
|
||||
/// # Example
|
||||
///
|
||||
/// ```rust
|
||||
/// ```
|
||||
/// fn foo(slice: &[int]) {}
|
||||
///
|
||||
/// let vec = vec![1i, 2];
|
||||
|
Loading…
Reference in New Issue
Block a user