Skip to content

Commit 4dc1225

Browse files
authored
Add helpful hint on io function for beginners
1 parent d558037 commit 4dc1225

File tree

1 file changed

+10
-0
lines changed

1 file changed

+10
-0
lines changed

src/libstd/io/mod.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -144,6 +144,16 @@
144144
//! # Ok(())
145145
//! # }
146146
//! ```
147+
//! Note that you cannot use the `?` operator in functions that do not return a `Result` (e.g. `main()`).
148+
//! Instead, you can `match` on the return value to catch any possible errors:
149+
//!
150+
//! ```
151+
//! let mut input = String::new();
152+
//! match io::stdin().read_line(&mut input) {
153+
//! Err(why) => panic!("Failed to read input: {}", why.description()),
154+
//! Ok(_) => println!("You typed: {}", input.trim()),
155+
//! }
156+
//! ```
147157
//!
148158
//! And a very common source of output is standard output:
149159
//!

0 commit comments

Comments
 (0)