Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
32 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,29 @@ | |||
fn o_ption() { | |||
println!("what's your name, noble worrior?"); | |||
let mut buf = String::new(); | |||
use std::io; | |||
io::stdin().read_line(&mut buf) | |||
.ok() | |||
.expect("Failed to read stdin"); | |||
let buf = buf.trim(); | |||
println!("{}, that's a mighty name indeeeeed.", buf); | |||
} | |||
|
|||
fn p_arse() { | |||
let mut buf = String::new(); | |||
println!("Enter a number: "); | |||
use std::io; | |||
io::stdin().read_line(&mut buf) | |||
.ok() | |||
.expect("Not a number!"); | |||
let input_num: Result<u32, _> = buf.trim().parse(); | |||
match input_num { | |||
Ok(num) => println!("You entered the number {}", num), | |||
Err(ex) => println!("Cannot be parsed as a number: {}", ex) | |||
}; | |||
} | |||
|
|||
fn main() { | |||
o_ption(); | |||
p_arse(); | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters