Skip to content

Instantly share code, notes, and snippets.

@swuecho
Forked from anonymous/playground.rs
Created December 14, 2017 17:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save swuecho/693c9af0ff9d713a1a6571122964b79e to your computer and use it in GitHub Desktop.
Save swuecho/693c9af0ff9d713a1a6571122964b79e 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