From 336dd16d05f34d12763e3db296a9ae438719a3d9 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Fri, 10 May 2024 01:03:00 -0300 Subject: [PATCH 1/3] Refactor examples and enhance documentation in result.rs --- library/core/src/result.rs | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/library/core/src/result.rs b/library/core/src/result.rs index b2b627fe6a9cc..7d651f7173baf 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -45,25 +45,29 @@ //! that make working with it more succinct. //! //! ``` +//! // The `is_ok` and `is_err` methods do what they say. //! let good_result: Result = Ok(10); //! let bad_result: Result = Err(10); -//! -//! // The `is_ok` and `is_err` methods do what they say. //! assert!(good_result.is_ok() && !good_result.is_err()); //! assert!(bad_result.is_err() && !bad_result.is_ok()); //! -//! // `map` consumes the `Result` and produces another. +//! // `map` and `map_err` consume the `Result` and produces another. //! let good_result: Result = good_result.map(|i| i + 1); -//! let bad_result: Result = bad_result.map(|i| i - 1); +//! let bad_result: Result = bad_result.map_err(|i| i - 1); +//! assert_eq!(good_result, Ok(11)); +//! assert_eq!(bad_result, Err(9)); //! //! // Use `and_then` to continue the computation. //! let good_result: Result = good_result.and_then(|i| Ok(i == 11)); +//! assert_eq!(good_result, Ok(true)); //! //! // Use `or_else` to handle the error. //! let bad_result: Result = bad_result.or_else(|i| Ok(i + 20)); +//! assert_eq!(bad_result, Ok(29)); //! //! // Consume the result and return the contents with `unwrap`. //! let final_awesome_result = good_result.unwrap(); +//! assert_eq!(final_awesome_result) //! ``` //! //! # Results must be used From 4a953dc5fffbd7dad1dd4ab278d57db11dfd4cf8 Mon Sep 17 00:00:00 2001 From: Renato Alves Date: Fri, 10 May 2024 08:10:30 -0300 Subject: [PATCH 2/3] Fix assert --- library/core/src/result.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/result.rs b/library/core/src/result.rs index 7d651f7173baf..c99de923d956b 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -67,7 +67,7 @@ //! //! // Consume the result and return the contents with `unwrap`. //! let final_awesome_result = good_result.unwrap(); -//! assert_eq!(final_awesome_result) +//! assert!(final_awesome_result) //! ``` //! //! # Results must be used From e1611aa690ccfa2e38b0041df90bca424809226d Mon Sep 17 00:00:00 2001 From: Renato A <63110187+prorealize@users.noreply.github.com> Date: Wed, 15 May 2024 08:07:16 -0300 Subject: [PATCH 3/3] Update library/core/src/result.rs Co-authored-by: joboet --- library/core/src/result.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/library/core/src/result.rs b/library/core/src/result.rs index c99de923d956b..4c6dc4bba4377 100644 --- a/library/core/src/result.rs +++ b/library/core/src/result.rs @@ -51,7 +51,7 @@ //! assert!(good_result.is_ok() && !good_result.is_err()); //! assert!(bad_result.is_err() && !bad_result.is_ok()); //! -//! // `map` and `map_err` consume the `Result` and produces another. +//! // `map` and `map_err` consume the `Result` and produce another. //! let good_result: Result = good_result.map(|i| i + 1); //! let bad_result: Result = bad_result.map_err(|i| i - 1); //! assert_eq!(good_result, Ok(11));