知识卡片

普通读书笔记卡 · 743.d.2

Result表达成功失败

理解等级:中级

Result把成功值放在Ok(T),失败信息放在Err(E),一个结果不会同时声称两者有效。标准枚举让调用方看见失败可能,也能复用变换与传播机制。它明确结果形状,却不决定应该重试、降级还是终止。

这张卡片看不懂?

已有反馈 · 0 / 10 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    • Chapter 1. Types Result<T, E> · 查看原书依据

      Result<T, E> The second common concept arises from error processing: if a function fails, how should that failure be reported? Historically, special sentinel values (e.g., -errno return values from Linux system calls) or global variables (errno for POSIX systems) were used. More recently, languages that support multiple or tuple return values (such as Go) fr

    参考来源

    - 位置:《Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)》第1章《Result<T, E>》(spine5;extracted/Effective Rust 35 Specific Ways to Improve Your Rust Code (David Drysdale)/_epub-src/OEBPS/ch01.html;u014-ch01-011)。 - 结论依据:原文在“Result<T, E>”附近的定义、例子或代码支撑本卡核心说明:Result<T,E>把成功值放在Ok(T),失败信息放在Err(E),一个结果不会同时声称两者有效。边界按已读前提解释;示例未执行。 - 原始内容:Result<T, E> The second common concept arises from error processing: if a function fails, how should that failure be reported? Historically, special sentinel values (e.g., -errno return values from Linux system calls) or global variables (errno for POSIX systems) were used. More recently, languages that support multiple or tuple return values (such as Go) fr