Skip to content

Commit 34520cf

Browse files
Mention unwrap() and expect()
1 parent 28eba7b commit 34520cf

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

src/language/nullability-and-optionality.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,9 +124,14 @@ lazily initialize the default value.
124124

125125
The null-forgiving operator (`!`) does not correspond to an equivalent construct
126126
in Rust, as it only affects the compiler's static flow analysis in C#. In Rust,
127-
there is no need to use a substitute for it.
127+
there is no need to use a substitute for it. [`unwrap`][opt_unwrap] is close,
128+
though: it panics if the value is `None`. [`expect`][opt_expect] is similar but allows
129+
you to provide a custom error message. Note that as previously said, panics should
130+
be reserved to unrecoverable situations.
128131

129132
[option]: https://doc.rust-lang.org/std/option/enum.Option.html
130133
[optmap]: https://doc.rust-lang.org/std/option/enum.Option.html#method.map
131134
[opt_and_then]: https://doc.rust-lang.org/std/option/enum.Option.html#method.and_then
132135
[unwrap-or]: https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap_or
136+
[opt_unwrap]: https://doc.rust-lang.org/std/option/enum.Option.html#method.unwrap
137+
[opt_expect]: https://doc.rust-lang.org/std/option/enum.Option.html#method.expect

0 commit comments

Comments
 (0)