Skip to content

Instantly share code, notes, and snippets.

Created December 14, 2017 17:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save anonymous/89c344af9fb8085137be73f43744b677 to your computer and use it in GitHub Desktop.
Save anonymous/89c344af9fb8085137be73f43744b677 to your computer and use it in GitHub Desktop.
Rust code shared from the playground
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