Skip to content

Commit 8f3e498

Browse files
authored
Improve code example for try!
This change improves the code example for try!, avoiding to use try! in the example code that shows what code constructs try! can replace.
1 parent 366de83 commit 8f3e498

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/libcore/result.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,8 +175,11 @@
175175
//! }
176176
//!
177177
//! fn write_info(info: &Info) -> io::Result<()> {
178-
//! let mut file = try!(File::create("my_best_friends.txt"));
179178
//! // Early return on error
179+
//! let mut file = match File::create("my_best_friends.txt") {
180+
//! Err(e) => return Err(e),
181+
//! Ok(f) => f,
182+
//! };
180183
//! if let Err(e) = file.write_all(format!("name: {}\n", info.name).as_bytes()) {
181184
//! return Err(e)
182185
//! }

0 commit comments

Comments
 (0)