Skip to content

Instantly share code, notes, and snippets.

@MatejLach
Created August 2, 2014 15:03
Show Gist options
  • Save MatejLach/d23e5ec019c48298045e to your computer and use it in GitHub Desktop.
Save MatejLach/d23e5ec019c48298045e to your computer and use it in GitHub Desktop.
Showcases standard input in Rust...
use std::io;
fn main() {
println!("Type something:");
let input = io::stdin()
.read_line() // read user input
.ok().expect("unable to read input!"); // Display this in case of a problem reading user input
// convert to &str and get rid of the newline
println!("You just typed \"{}\" into the console.\nCongratulations!", input.as_slice().trim_right_chars('\n'));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment