知识卡片

普通读书笔记卡 · 743.d.6.a.1

迭代接口分开产生与推进

理解等级:中级

IntoIterator提供into_iter产生迭代器,Iterator再通过next逐项返回Option,for将None视为结束。迭代器不一定来自容器,也可计算生成值;一般Iterator在None后是否永远结束还需相应保证,不能仅凭方法名推断。

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 1. Types Iterator Traits · 查看原书依据

      Iterator Traits The core Iterator trait has a very simple interface: a single method next that yields Some items until it doesn’t (None). The type of the emitted items is given by the trait’s associated Item type. Collections that allow iteration over their contents—what would be called iterables in other languages—implement the IntoIterator trait; the into_

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第1章《Iterator Traits》(spine5;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch01.html;u048-ch01-072)。 - 结论依据:原文在“Iterator Traits”附近的定义、例子或代码支撑本卡核心说明:IntoIterator提供into_iter产生迭代器,Iterator再通过next逐项返回Option<Item>,for将None视为结束。边界按已读前提解释;示例未执行。 - 原始内容:Iterator Traits The core Iterator trait has a very simple interface: a single method next that yields Some items until it doesn’t (None). The type of the emitted items is given by the trait’s associated Item type. Collections that allow iteration over their contents—what would be called iterables in other languages—implement the IntoIterator trait; the into_