Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make rust editable in chapter on defaults #1589

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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