about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJupp Müller <jupp0r@gmail.com>2016-06-29 01:13:03 +0200
committerGitHub <noreply@github.com>2016-06-29 01:13:03 +0200
commit8f3e4989a5253f3baac79b8ee27a47aec53c0159 (patch)
tree7cc2e2f65fdf98f133bb6be10cc67ecf2ec55c7f
parent366de839ae9794411419c5b579c829e18adde613 (diff)
downloadrust-8f3e4989a5253f3baac79b8ee27a47aec53c0159.tar.gz
rust-8f3e4989a5253f3baac79b8ee27a47aec53c0159.zip
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.
-rw-r--r--src/libcore/result.rs5
1 files changed, 4 insertions, 1 deletions
diff --git a/src/libcore/result.rs b/src/libcore/result.rs
index 4d9f042fdde..94c6c636ce8 100644
--- a/src/libcore/result.rs
+++ b/src/libcore/result.rs
@@ -175,8 +175,11 @@
 //! }
 //!
 //! fn write_info(info: &Info) -> io::Result<()> {
-//!     let mut file = try!(File::create("my_best_friends.txt"));
 //!     // Early return on error
+//!     let mut file = match File::create("my_best_friends.txt") {
+//!            Err(e) => return Err(e),
+//!            Ok(f) => f,
+//!     };
 //!     if let Err(e) = file.write_all(format!("name: {}\n", info.name).as_bytes()) {
 //!         return Err(e)
 //!     }