Skip to content

Commit 1c9a496

Browse files
committed
chore(code-style-guide): Use link definitions
1 parent 0929018 commit 1c9a496

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

modules/contributor/pages/code-style-guide.adoc

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -533,11 +533,13 @@ enum Error {
533533

534534
=== Using `unwrap`
535535

536+
:unwrap_or: https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_or
537+
:unwrap_or_default: https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_or_default
538+
:unwrap_or_else: https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_or_else
539+
536540
The `unwrap` function must not be used in any fallible code paths.
537541
Instead, proper error handling like above should be used, unless there is a valid reason to use `expect` described below.
538-
Using https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_or[`unwrap_or`], https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_or_default[`unwrap_or_default`] or https://doc.rust-lang.org/std/result/enum.Result.html#method.unwrap_or_else[`unwrap_or_else`] is allowed because these functions will not panic.
539-
540-
There are however cases, where it is fine to use `unwrap` or friends.
542+
Using link:{unwrap_or}[`unwrap_or`], link:{unwrap_or_default}[`unwrap_or_default`] or link:{unwrap_or_else}[`unwrap_or_else`] is allowed because these functions will not panic.
541543

542544
The `expect` function can be used when external factors cannot influence whether a panic will happen. For example, when compiling regular expressions inside const/static environments.
543545
For such cases code must use `expect` instead of `unwrap` to provide additional context for why a particular piece of code should never fail.

0 commit comments

Comments
 (0)