Skip to content

Instantly share code, notes, and snippets.

@swuecho
Forked from anonymous/playground.rs
Created December 14, 2017 17:22
Show Gist options
  • Select an option

  • Save swuecho/693c9af0ff9d713a1a6571122964b79e to your computer and use it in GitHub Desktop.

Select an option

Save swuecho/693c9af0ff9d713a1a6571122964b79e to your computer and use it in GitHub Desktop.

Revisions

  1. @invalid-email-address Anonymous created this gist Dec 14, 2017.
    17 changes: 17 additions & 0 deletions playground.rs
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,17 @@
    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)
    }
    }