From fa7e4f8ade33fc67966604e54adb63bc1a992537 Mon Sep 17 00:00:00 2001 From: breayhing <1519981563@qq.com> Date: Thu, 11 Jul 2024 22:02:46 +0800 Subject: [PATCH] :bug: fix bugs --- solutions/12_options/options4.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/solutions/12_options/options4.rs b/solutions/12_options/options4.rs index da8315aa..97291e74 100644 --- a/solutions/12_options/options4.rs +++ b/solutions/12_options/options4.rs @@ -10,7 +10,7 @@ fn main() { // Exercise 1: Use ok_or to convert optional_point to a Result. // If the point exists, print its coordinates. // If it doesn't, print the error message "Point does not exist". - let result_point = optional_point.ok_or("Point does not exist"); + let result_point = optional_point.clone().ok_or("Point does not exist"); match result_point { Ok(p) => println!("Co-ordinates are {},{}", p.x, p.y), Err(e) => println!("{}", e), @@ -18,7 +18,7 @@ fn main() { // Exercise 2: Use ok_or_else to achieve the same functionality as above, // but with a closure to generate the error message. - let result_point_else = optional_point.ok_or_else(|| "Point does not exist"); + let result_point_else = optional_point.clone().ok_or_else(|| "Point does not exist"); match result_point_else { Ok(p) => println!("Co-ordinates are {},{}", p.x, p.y), Err(e) => println!("{}", e), @@ -27,7 +27,7 @@ fn main() { // Exercise 3: Use and_then to chain operations on optional_point. // If the point exists, compute the distance from the origin and return it as an Option. // If it doesn't, return None. - let distance_from_origin = optional_point.and_then(|p| { + let distance_from_origin = optional_point.clone().and_then(|p| { let distance = ((p.x.pow(2) + p.y.pow(2)) as f64).sqrt(); Some(distance) });