summaryrefslogtreecommitdiff
path: root/meap/meap-code/ch2/ch2-match-needles.rs
blob: ab999f3fe719e1aa80287fce8192294affcc8b0f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
fn main() {
  // let needle = 42; // <1>
  let haystack = [1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862];
    
  for reference in haystack.iter() {
    let item = *reference;
    
    let result = match item { // <2>
      42 | 132 => "hit!", // <3>
      _ => "miss", // <4>
    };
    
    if result == "hit!" {
      println!("{}: {}", item, result);
    }
  }
}