提交 df8dd3fd 编写于 作者: T Tshepang Lekhonkhobe

doc: no need for the references

Also:
- apply some rustfmt love
- fix output of one example
上级 29f5c699
......@@ -1180,19 +1180,19 @@ fn fuse(self) -> Fuse<Self> where Self: Sized {
///
/// // this iterator sequence is complex.
/// let sum = a.iter()
/// .cloned()
/// .filter(|&x| x % 2 == 0)
/// .fold(0, |sum, i| sum + i);
/// .cloned()
/// .filter(|x| x % 2 == 0)
/// .fold(0, |sum, i| sum + i);
///
/// println!("{}", sum);
///
/// // let's add some inspect() calls to investigate what's happening
/// let sum = a.iter()
/// .cloned()
/// .inspect(|x| println!("about to filter: {}", x))
/// .filter(|&x| x % 2 == 0)
/// .inspect(|x| println!("made it through filter: {}", x))
/// .fold(0, |sum, i| sum + i);
/// .cloned()
/// .inspect(|x| println!("about to filter: {}", x))
/// .filter(|x| x % 2 == 0)
/// .inspect(|x| println!("made it through filter: {}", x))
/// .fold(0, |sum, i| sum + i);
///
/// println!("{}", sum);
/// ```
......@@ -1200,6 +1200,7 @@ fn fuse(self) -> Fuse<Self> where Self: Sized {
/// This will print:
///
/// ```text
/// 6
/// about to filter: 1
/// about to filter: 4
/// made it through filter: 4
......@@ -1230,8 +1231,7 @@ fn inspect<F>(self, f: F) -> Inspect<Self, F> where
///
/// let iter = a.into_iter();
///
/// let sum: i32 = iter.take(5)
/// .fold(0, |acc, &i| acc + i );
/// let sum: i32 = iter.take(5).fold(0, |acc, i| acc + i );
///
/// assert_eq!(sum, 6);
///
......@@ -1245,9 +1245,7 @@ fn inspect<F>(self, f: F) -> Inspect<Self, F> where
/// let mut iter = a.into_iter();
///
/// // instead, we add in a .by_ref()
/// let sum: i32 = iter.by_ref()
/// .take(2)
/// .fold(0, |acc, &i| acc + i );
/// let sum: i32 = iter.by_ref().take(2).fold(0, |acc, i| acc + i );
///
/// assert_eq!(sum, 3);
///
......@@ -1304,9 +1302,7 @@ fn by_ref(&mut self) -> &mut Self where Self: Sized { self }
///
/// let a = [1, 2, 3];
///
/// let doubled: VecDeque<i32> = a.iter()
/// .map(|&x| x * 2)
/// .collect();
/// let doubled: VecDeque<i32> = a.iter().map(|&x| x * 2).collect();
///
/// assert_eq!(2, doubled[0]);
/// assert_eq!(4, doubled[1]);
......@@ -1318,9 +1314,7 @@ fn by_ref(&mut self) -> &mut Self where Self: Sized { self }
/// ```
/// let a = [1, 2, 3];
///
/// let doubled = a.iter()
/// .map(|&x| x * 2)
/// .collect::<Vec<i32>>();
/// let doubled = a.iter().map(|x| x * 2).collect::<Vec<i32>>();
///
/// assert_eq!(vec![2, 4, 6], doubled);
/// ```
......@@ -1331,9 +1325,7 @@ fn by_ref(&mut self) -> &mut Self where Self: Sized { self }
/// ```
/// let a = [1, 2, 3];
///
/// let doubled = a.iter()
/// .map(|&x| x * 2)
/// .collect::<Vec<_>>();
/// let doubled = a.iter().map(|x| x * 2).collect::<Vec<_>>();
///
/// assert_eq!(vec![2, 4, 6], doubled);
/// ```
......@@ -1344,9 +1336,9 @@ fn by_ref(&mut self) -> &mut Self where Self: Sized { self }
/// let chars = ['g', 'd', 'k', 'k', 'n'];
///
/// let hello: String = chars.iter()
/// .map(|&x| x as u8)
/// .map(|x| (x + 1) as char)
/// .collect();
/// .map(|&x| x as u8)
/// .map(|x| (x + 1) as char)
/// .collect();
///
/// assert_eq!("hello", hello);
/// ```
......@@ -1393,8 +1385,9 @@ fn collect<B: FromIterator<Self::Item>>(self) -> B where Self: Sized {
/// ```
/// let a = [1, 2, 3];
///
/// let (even, odd): (Vec<i32>, Vec<i32>) = a.into_iter()
/// .partition(|&n| n % 2 == 0);
/// let (even, odd): (Vec<i32>, Vec<i32>) = a
/// .into_iter()
/// .partition(|&n| n % 2 == 0);
///
/// assert_eq!(even, vec![2]);
/// assert_eq!(odd, vec![1, 3]);
......@@ -1457,8 +1450,7 @@ fn partition<B, F>(self, mut f: F) -> (B, B) where
/// let a = [1, 2, 3];
///
/// // the checked sum of all of the elements of the array
/// let sum = a.iter()
/// .try_fold(0i8, |acc, &x| acc.checked_add(x));
/// let sum = a.iter().try_fold(0i8, |acc, &x| acc.checked_add(x));
///
/// assert_eq!(sum, Some(6));
/// ```
......@@ -1556,8 +1548,7 @@ fn try_for_each<F, R>(&mut self, mut f: F) -> R where
/// let a = [1, 2, 3];
///
/// // the sum of all of the elements of the array
/// let sum = a.iter()
/// .fold(0, |acc, &x| acc + x);
/// let sum = a.iter().fold(0, |acc, x| acc + x);
///
/// assert_eq!(sum, 6);
/// ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册