Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,853 questions

51,774 answers

573 users

How to use match statement (switch statement) in Rust

2 Answers

0 votes
fn main() {
    let code = "Z09";
    let state = match code {
      "X03" => {println!("Found match to X03"); "XO3 Code"},
      "Y07" => "Y07 Code",
      "Z09" => {println!("Found match to Z09"); "Z09 Code"},
      "V01" => "V01 Code",
      _ => "Unknown"
   };
   
   println!("State = {}", state);
}




/*
run:

Found match to Z09
State = Z09 Code

*/

 



answered Oct 23, 2022 by avibootz
0 votes
const A: i32 = 546;
const B: i32 = 901;
const C: i32 = set_c();

const fn set_c() -> i32 {
    A + B
}

fn main() {
    for &value in &[546, 901, 1447, 5] {
        match value {
            A => println!("value = a"),
            B => println!("value = b"),
            C => println!("value = c"),
            _ => println!("value not equal any number"),
        }
    }
}




/*
run:

value = a
value = b
value = c
value not equal any number

*/

 



answered Oct 23, 2022 by avibootz
edited Oct 23, 2022 by avibootz

Related questions

1 answer 66 views
1 answer 143 views
143 views asked Oct 23, 2022 by avibootz
...