Skip to content

Commit a9fb7d1

Browse files
authored
Merge pull request #1664 from tburko/fix-get_or_insert-example
get_or_insert example: print my_fruit as intended
2 parents f06f449 + 80ca952 commit a9fb7d1

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/error/option_unwrap/defaults.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ fn main() {
6363
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 evaluates its parameter, so variable `apple` is moved:
6464

6565
```rust,editable
66-
#[derive(Debug)]
66+
#[derive(Debug)]
6767
enum Fruit { Apple, Orange, Banana, Kiwi, Lemon }
6868
6969
fn main() {
7070
let mut my_fruit: Option<Fruit> = None;
7171
let apple = Fruit::Apple;
7272
let first_available_fruit = my_fruit.get_or_insert(apple);
73-
println!("my_fruit is: {:?}", first_available_fruit);
7473
println!("first_available_fruit is: {:?}", first_available_fruit);
75-
// my_fruit is: Apple
74+
println!("my_fruit is: {:?}", my_fruit);
7675
// first_available_fruit is: Apple
76+
// my_fruit is: Some(Apple)
7777
//println!("Variable named `apple` is moved: {:?}", apple);
7878
// TODO: uncomment the line above to see the compiler error
7979
}

0 commit comments

Comments
 (0)