Skip to content

Instantly share code, notes, and snippets.

@MatejLach
Created July 23, 2014 12:35
Show Gist options
  • Save MatejLach/e5eb335aee6aaa33e383 to your computer and use it in GitHub Desktop.
Save MatejLach/e5eb335aee6aaa33e383 to your computer and use it in GitHub Desktop.
Pattern matching in Rust...
fn main() {
let x = 3.75f64;
match x {
1.0..1.99 => println!("x is between one and two"),
2.0..2.99 => println!("x is between two and three"),
3.0..3.99 => println!("x is between three and four"),
4.0..4.99 => println!("x is between four and five"),
5.0..5.99 => println!("x is between five and six"),
_ => println!("x is bigger than five") // catches all other possible values of `x`
}
}
Copy link

ghost commented Feb 1, 2015

the latest working code should be like this

fn main() {
    let x = 3.75f64;

    match x {
        1.0...1.99 => println!("x is between one and two"),
        2.0...2.99 => println!("x is between two and three"),
        3.0...3.99 => println!("x is between three and four"),
        4.0...4.99 => println!("x is between four and five"),
        5.0...5.99 => println!("x is between five and six"),
        _ => println!("x is bigger than five") // catches all other possible values of `x`
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment