Skip to content

Commit

Permalink
Update ch13-02-iterators.md
Browse files Browse the repository at this point in the history
消耗迭代器 -> 消费迭代器
  • Loading branch information
sighttview authored Mar 1, 2024
1 parent 8a2abe8 commit 19e20fa
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/ch13-02-iterators.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ fn iterator_demonstration() {

`Iterator` trait 有一系列不同的由标准库提供默认实现的方法;你可以在 `Iterator` trait 的标准库 API 文档中找到所有这些方法。一些方法在其定义中调用了 `next` 方法,这就是为什么在实现 `Iterator` trait 时要求实现 `next` 方法。

这些调用 `next` 方法的方法被称为 **消费适配器***consuming adaptors*),因为调用他们会消耗迭代器。一个消费适配器的例子是 `sum` 方法。这个方法获取迭代器的所有权并反复调用 `next` 来遍历迭代器,因而会消费迭代器。当其遍历每一个项时,它将每一个项加总到一个总和并在迭代完成时返回总和。示例 13-16 有一个展示 `sum` 方法使用的测试:
这些调用 `next` 方法的方法被称为 **消费适配器***consuming adaptors*),因为调用他们会消费迭代器。一个消费适配器的例子是 `sum` 方法。这个方法获取迭代器的所有权并反复调用 `next` 来遍历迭代器,因而会消费迭代器。当其遍历每一个项时,它将每一个项加总到一个总和并在迭代完成时返回总和。示例 13-16 有一个展示 `sum` 方法使用的测试:

<span class="filename">文件名: src/lib.rs</span>

Expand Down

0 comments on commit 19e20fa

Please sign in to comment.