Skip to content

Commit

Permalink
Refactor examples and enhance documentation in result.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
prorealize committed May 10, 2024
1 parent a6e87c5 commit 336dd16
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions library/core/src/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<i32, i32> = Ok(10);
//! let bad_result: Result<i32, i32> = 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<i32, i32> = good_result.map(|i| i + 1);
//! let bad_result: Result<i32, i32> = bad_result.map(|i| i - 1);
//! let bad_result: Result<i32, i32> = 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<bool, i32> = 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<i32, i32> = 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)

Check failure on line 70 in library/core/src/result.rs

View workflow job for this annotation

GitHub Actions / PR - mingw-check

unexpected end of macro invocation
//! ```
//!
//! # Results must be used
Expand Down

0 comments on commit 336dd16

Please sign in to comment.