From 88a102ef785b4ea30d23b9350f8ed45e2e9d668a Mon Sep 17 00:00:00 2001 From: Taras Burko Date: Tue, 10 Jan 2023 15:12:20 +0000 Subject: [PATCH 1/2] get_or_insert example: print my_fruit as intended --- src/error/option_unwrap/defaults.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/error/option_unwrap/defaults.md b/src/error/option_unwrap/defaults.md index 4d3a60f9d6..b0874cd9ba 100644 --- a/src/error/option_unwrap/defaults.md +++ b/src/error/option_unwrap/defaults.md @@ -70,7 +70,7 @@ fn main() { let mut my_fruit: Option = None; let apple = Fruit::Apple; let first_available_fruit = my_fruit.get_or_insert(apple); - println!("my_fruit is: {:?}", first_available_fruit); + println!("my_fruit is: {:?}", my_fruit); println!("first_available_fruit is: {:?}", first_available_fruit); // my_fruit is: Apple // first_available_fruit is: Apple From 80ca9529eaee84094dadb6c9900d066b3b3c7cfe Mon Sep 17 00:00:00 2001 From: Taras Burko Date: Tue, 10 Jan 2023 15:25:18 +0000 Subject: [PATCH 2/2] fix print order, fix output format --- src/error/option_unwrap/defaults.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/error/option_unwrap/defaults.md b/src/error/option_unwrap/defaults.md index b0874cd9ba..4c1844a20c 100644 --- a/src/error/option_unwrap/defaults.md +++ b/src/error/option_unwrap/defaults.md @@ -63,17 +63,17 @@ fn main() { 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: ```rust,editable -#[derive(Debug)] +#[derive(Debug)] enum Fruit { Apple, Orange, Banana, Kiwi, Lemon } fn main() { let mut my_fruit: Option = None; let apple = Fruit::Apple; let first_available_fruit = my_fruit.get_or_insert(apple); - println!("my_fruit is: {:?}", my_fruit); println!("first_available_fruit is: {:?}", first_available_fruit); - // my_fruit is: Apple + println!("my_fruit is: {:?}", my_fruit); // first_available_fruit is: Apple + // my_fruit is: Some(Apple) //println!("Variable named `apple` is moved: {:?}", apple); // TODO: uncomment the line above to see the compiler error }