知识卡片

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

可失败迭代在首错停止

理解等级:中级

try_for_each与try_fold允许逐项操作返回失败,遇到首个失败时停止并交回该失败,适合需要明确终止的处理。它们不自动回滚已执行的副作用。书中并列的try_find有工具链稳定性限制,使用前须核对目标版本,不能把列举等同于稳定可用。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

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

      try_for_each(f) Behaves like for_each, but the closure can fail try_fold(f) Behaves like fold, but the closure can fail try_find(f) Behaves like find, but the closure can fail Finally, there are methods that accumulate all of the iterated items into a new collection. The most important of these is collect(), which can be used to build a new instance of any c

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第1章《Iterator Consumers》(spine5;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch01.html;u050-ch01-079)。 - 结论依据:原文在“try_for_each(f)”附近的定义、例子或代码支撑本卡核心说明:try_for_each与try_fold允许逐项操作返回失败,遇到首个失败时停止并交回该失败,适合需要明确终止的处理。边界按已读前提解释;示例未执行。 - 原始内容:try_for_each(f) Behaves like for_each, but the closure can fail try_fold(f) Behaves like fold, but the closure can fail try_find(f) Behaves like find, but the closure can fail Finally, there are methods that accumulate all of the iterated items into a new collection. The most important of these is collect(), which can be used to build a new instance of any c