Skip to content

Rust:match

springroll edited this page Dec 9, 2019 · 1 revision

match

Overview

パターンマッチングについて

Code

  • 文字列のパターンマッチング
fn main(){
    let s:String = read();

    let res = match &s[..] {
        "one" => 1,
        "two" => 2,
        "three" => 3,
        _ => -1,
    };
    println!("{}", res);
}

Detail

Clone this wiki locally