You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/error/option_unwrap/defaults.md
+6-6Lines changed: 6 additions & 6 deletions
Original file line number
Diff line number
Diff line change
@@ -8,7 +8,7 @@ The is more than one way to unpack an `Option` and fall back on a default if it
8
8
9
9
`or()`is chainable and eagerly evaluates its argument, as is shown in the following example. Note that because `or`'s arguments are evaluated eagerly, the variable passed to `or` is moved.
10
10
11
-
```
11
+
```rust,editable
12
12
#[derive(Debug)]
13
13
enum Fruit { Apple, Orange, Banana, Kiwi, Lemon }
14
14
@@ -33,7 +33,7 @@ fn main() {
33
33
34
34
Another alternative is to use `or_else`, which is also chainable, and evaluates lazily, as is shown in the following example:
35
35
36
-
```
36
+
```rust,editable
37
37
#[derive(Debug)]
38
38
enum Fruit { Apple, Orange, Banana, Kiwi, Lemon }
39
39
@@ -58,11 +58,11 @@ fn main() {
58
58
}
59
59
```
60
60
61
-
## `get_or_insert()` evaluates eagerly, modifies empty value im place
61
+
## `get_or_insert()` evaluates eagerly, modifies empty value in place
62
62
63
63
To make sure that an `Option` contains a value, we can use `get_or_insert` to modify it in place with a fallback value, as is shown in the following example. Note that `get_or_insert` eagerly evaluaes its parameter, so variable `apple` is moved:
64
64
65
-
```
65
+
```rust,editable
66
66
#[derive(Debug)]
67
67
enum Fruit { Apple, Orange, Banana, Kiwi, Lemon }
68
68
@@ -79,10 +79,10 @@ fn main() {
79
79
}
80
80
```
81
81
82
-
## `get_or_insert_with()` evaluates lazily, modifies empty value im place
82
+
## `get_or_insert_with()` evaluates lazily, modifies empty value in place
83
83
84
84
Instead of explicitly providing a value to fall back on, we can pass a closure to `get_or_insert_with`, as follows:
0 commit comments