Skip to content

Instantly share code, notes, and snippets.

@Mech0n
Last active February 1, 2022 10:16
Show Gist options
  • Save Mech0n/6367615543adfba81c6643b83ddcae69 to your computer and use it in GitHub Desktop.
Save Mech0n/6367615543adfba81c6643b83ddcae69 to your computer and use it in GitHub Desktop.
@Mech0n
Copy link
Author

Mech0n commented Feb 1, 2022

2022.2.1

? Operator

把 result 用 match 连接起来会显得很难看;幸运的是,? 运算符可以把这种逻辑变得 干净漂亮。? 运算符用在返回值为 Result 的表达式后面,它等同于这样一个匹配 表达式:其中 Err(err) 分支展开成提前返回的 return Err(err),而 Ok(ok) 分支展开成 ok 表达式。

?用法

在 Rust 标准库中可能产生异常的函数的返回值都是 Result 类型的。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment