From c517ea2d22ce3b021869f5cded4ca00a55151fb1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chu=C3=A1nq=C3=AD=20Sun?= <1895289+chuanqisun@users.noreply.github.com> Date: Thu, 29 Dec 2022 20:17:45 -0800 Subject: [PATCH 1/2] Fix sample code mismatching its comments Print `my_fruit` instead of `first_available_fruit`. However, I need to swap the order of the two prints to avoid borrow checker issue --- src/error/option_unwrap/defaults.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/error/option_unwrap/defaults.md b/src/error/option_unwrap/defaults.md index 117333f120..ce03676439 100644 --- a/src/error/option_unwrap/defaults.md +++ b/src/error/option_unwrap/defaults.md @@ -94,11 +94,11 @@ fn main() { }; let first_available_fruit = my_fruit .get_or_insert_with(get_lemon_as_fallback); - println!("my_fruit is: {:?}", first_available_fruit); println!("first_available_fruit is: {:?}", first_available_fruit); + println!("my_fruit is: {:?}", my_fruit); // Providing lemon as fallback - // my_fruit is: Lemon // first_available_fruit is: Lemon + // my_fruit is: Lemon // If the Option has a value, it is left unchanged, and the closure is not invoked let mut my_apple = Some(Fruit::Apple); From 5561d7e3d2cdec5f8a5d05fb6b880bc362a822e3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Chu=C3=A1nq=C3=AD=20Sun?= <1895289+chuanqisun@users.noreply.github.com> Date: Thu, 29 Dec 2022 20:19:59 -0800 Subject: [PATCH 2/2] Update defaults.md --- 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 ce03676439..4d3a60f9d6 100644 --- a/src/error/option_unwrap/defaults.md +++ b/src/error/option_unwrap/defaults.md @@ -98,7 +98,7 @@ fn main() { println!("my_fruit is: {:?}", my_fruit); // Providing lemon as fallback // first_available_fruit is: Lemon - // my_fruit is: Lemon + // my_fruit is: Some(Lemon) // If the Option has a value, it is left unchanged, and the closure is not invoked let mut my_apple = Some(Fruit::Apple);