Skip to content

Commit 1217007

Browse files
committed
Use if-let in std::result documentation
This takes an opportunity to show yet-another-way of dealing with Results and matching.
1 parent 064c21e commit 1217007

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

src/libcore/result.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,13 +178,11 @@
178178
//! fn write_info(info: &Info) -> Result<(), IoError> {
179179
//! let mut file = File::open_mode(&Path::new("my_best_friends.txt"), Open, Write);
180180
//! // Early return on error
181-
//! match file.write_line(format!("name: {}", info.name).as_slice()) {
182-
//! Ok(_) => (),
183-
//! Err(e) => return Err(e)
181+
//! if let Err(e) = file.write_line(format!("name: {}", info.name).as_slice()) {
182+
//! return Err(e)
184183
//! }
185-
//! match file.write_line(format!("age: {}", info.age).as_slice()) {
186-
//! Ok(_) => (),
187-
//! Err(e) => return Err(e)
184+
//! if let Err(e) = file.write_line(format!("age: {}", info.age).as_slice()) {
185+
//! return Err(e)
188186
//! }
189187
//! return file.write_line(format!("rating: {}", info.rating).as_slice());
190188
//! }

0 commit comments

Comments
 (0)