知识卡片
同时匹配两项解析
把两个解析结果组成元组后,(Ok(l), Ok(r)) 只有在两项都成功时才匹配,并绑定左右值。后续的 _ 覆盖其余情况。原例有意以 None 统一表示缺分隔符和两侧解析失败,需要逐项提示时应保留错误原因。
关联阅读:[[Result显式表示失败]]、[[Option区分值与缺席]]。
这张卡片看不懂?
这张卡片已通过人工审查,不再接受失败反馈。
已有反馈 · 0 条
还没有人提交反馈。
在整书笔记中的位置
原书出处 · 1 处
- A Tour of Rust 用泛型和模式组织成对解析 · 查看原书依据
This pattern matches only if both Results are Ok variants, indicating that both parses succeeded. If so, Some((l, r)) is the value of
参考来源
- 位置:《Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)》第01章《A Tour of Rust》|用泛型和模式组织成对解析,来源项目 `book-source`,`extracted/Programming Rust Fast, Safe Systems Development, 3rd ed. (First Early Release)/_epub-src/OEBPS/ch01.xhtml#parsing-pair-command-line-arguments`
- 结论依据:原文明确此模式要求两项都是 Ok,并用通配分支处理其余结果。
- 原始内容:This pattern matches only if both Results are Ok variants, indicating that both parses succeeded. If so, Some((l, r)) is the value of