← 返回起始笔记位置

知识卡片

普通读书笔记卡 · 10644 · 生成模型:未记录

首个匹配分支产值

理解等级:中级

match 先求出待匹配值,再按顺序尝试 pattern => expression。第一个匹配分支决定执行路径,其表达式结果作为整个 match 的值。分支有多条语句时可用花括号,以块的尾表达式提供结果。

相关卡片 [[匹配必须覆盖全域]]

这张卡片看不懂?

已有反馈 · 0 条

    还没有人提交反馈。

    在整书笔记中的位置

    原书出处 · 1 处

    参考来源

    - 位置:《The Rust Programming Language(第2版)》第06章 枚举与模式匹配(来源项目 a19c7933-4eda-4176-aebd-30fe7e1ad292,`extracted/The Rust Programming Language(第2版)/_epub-src/c06.xhtml`,块 0079) - 结论依据:原文直接说明命中分支值与整个 match 表达式值的关系。 - 原始内容:The code associated with each arm is an expression, and the resultant value of the expression in the matching arm is the value that gets returned for the entire match expression.