Skip to content

Commit

Permalink
Make rust editable in chapter on defaults (#1589)
Browse files Browse the repository at this point in the history
* make-rust-editable-in-chapter-on-defaults

* im-to-in-fix-typo
  • Loading branch information
AlexCue987 committed Aug 10, 2022
1 parent ee342dc commit ec44dbf
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/error/option_unwrap/defaults.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The is more than one way to unpack an `Option` and fall back on a default if it

`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.

```
```rust,editable
#[derive(Debug)]
enum Fruit { Apple, Orange, Banana, Kiwi, Lemon }
Expand All @@ -33,7 +33,7 @@ fn main() {

Another alternative is to use `or_else`, which is also chainable, and evaluates lazily, as is shown in the following example:

```
```rust,editable
#[derive(Debug)]
enum Fruit { Apple, Orange, Banana, Kiwi, Lemon }
Expand All @@ -58,11 +58,11 @@ fn main() {
}
```

## `get_or_insert()` evaluates eagerly, modifies empty value im place
## `get_or_insert()` evaluates eagerly, modifies empty value in place

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:

```
```rust,editable
#[derive(Debug)]
enum Fruit { Apple, Orange, Banana, Kiwi, Lemon }
Expand All @@ -79,10 +79,10 @@ fn main() {
}
```

## `get_or_insert_with()` evaluates lazily, modifies empty value im place
## `get_or_insert_with()` evaluates lazily, modifies empty value in place

Instead of explicitly providing a value to fall back on, we can pass a closure to `get_or_insert_with`, as follows:
```
```rust,editable
#[derive(Debug)]
enum Fruit { Apple, Orange, Banana, Kiwi, Lemon }
Expand Down

0 comments on commit ec44dbf

Please sign in to comment.