Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
df8dd3fd
R
Rust
项目概览
int
/
Rust
接近 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
df8dd3fd
编写于
2月 28, 2018
作者:
T
Tshepang Lekhonkhobe
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
doc: no need for the references
Also: - apply some rustfmt love - fix output of one example
上级
29f5c699
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
22 addition
and
31 deletion
+22
-31
src/libcore/iter/iterator.rs
src/libcore/iter/iterator.rs
+22
-31
未找到文件。
src/libcore/iter/iterator.rs
浏览文件 @
df8dd3fd
...
...
@@ -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.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录