We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 0d0ce84 commit a43b5b1Copy full SHA for a43b5b1
README.md
@@ -13,4 +13,5 @@ in a controlled repository now.
13
* `closures.rs`: closure examples
14
* `lifetimes.rs`: simple lifetime example
15
* `rc`: examples with `RefCell` and `Rc`
16
+* `readline`: example of readline with error handling
17
* `error`: example of creating a custom error
readline.rs
@@ -0,0 +1,16 @@
1
+/// Read from stdin with default.
2
+fn main() {
3
+ use std::io::BufRead;
4
+ let stdin = std::io::stdin();
5
+ let mut stdin = stdin.lock();
6
+ let mut line = String::new();
7
+ match stdin.read_line(&mut line) {
8
+ Ok(_) => {
9
+ print!("{}", line);
10
+ }
11
+ Err(e) => {
12
+ eprintln!("read_line: {}", e);
+ std::process::exit(1);
+}
0 commit comments