summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorNick Sweeting <git@nicksweeting.com>2017-03-23 13:17:21 -0400
committerGitHub <noreply@github.com>2017-03-23 13:17:21 -0400
commit4dc122580714a5f8859e993bf56a7228b0bcd7c1 (patch)
tree61e2e8afb45ff8a15f7098ff0eb6934da90044ff /src/libstd
parentd5580374d7eb8795a8188be4650bd5079a25c6b3 (diff)
downloadrust-4dc122580714a5f8859e993bf56a7228b0bcd7c1.tar.gz
rust-4dc122580714a5f8859e993bf56a7228b0bcd7c1.zip
Add helpful hint on io function for beginners
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/io/mod.rs10
1 files changed, 10 insertions, 0 deletions
diff --git a/src/libstd/io/mod.rs b/src/libstd/io/mod.rs
index 850885a8c0f..dda9d6bca79 100644
--- a/src/libstd/io/mod.rs
+++ b/src/libstd/io/mod.rs
@@ -144,6 +144,16 @@
 //! # Ok(())
 //! # }
 //! ```
+//! Note that you cannot use the `?` operator in functions that do not return a `Result` (e.g. `main()`).
+//! Instead, you can `match` on the return value to catch any possible errors:
+//! 
+//! ```
+//! let mut input = String::new();
+//! match io::stdin().read_line(&mut input) {
+//!     Err(why) => panic!("Failed to read input: {}", why.description()),
+//!     Ok(_) => println!("You typed: {}", input.trim()),
+//! }
+//! ```
 //!
 //! And a very common source of output is standard output:
 //!