-
-
Save swuecho/693c9af0ff9d713a1a6571122964b79e to your computer and use it in GitHub Desktop.
Rust code shared from the playground
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
use std::str::FromStr; | |
fn main () { | |
let mut input = "15 Bear".split(' '); | |
// Need to pull the number and parse it. | |
let number = input.next() | |
// Process Option<&'static str> to Option<int> | |
.and_then(|x| i32::from_str(x).ok() ) | |
.expect("Was not provided a valid number."); | |
// The next token is our animal. | |
let animal = input.next() | |
.expect("Was not provided an animal."); | |
// Ouput `number` times. | |
for x in 0 .. number { | |
println!("{} {} says hi!", animal, x) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment