Skip to content

Commit

Permalink
ch2: add ch2-needle-in-haystack.rs example
Browse files Browse the repository at this point in the history
  • Loading branch information
timClicks authored Jun 30, 2022
1 parent eb41d1f commit aff3c02
Showing 1 changed file with 15 additions and 0 deletions.
15 changes: 15 additions & 0 deletions ch2/ch2-needle-in-haystack.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
fn main() {
let needle = 42;
let haystack = [1, 1, 2, 5, 14, 42, 132, 429, 1430, 4862]; // <1>

for reference in haystack.iter() { // <2>
let item = *reference; // <3>
if item == needle {
println!("{}", item);
}

// if reference == &needle { // <4>
// println!("{}", reference);
// }
}
}

0 comments on commit aff3c02

Please sign in to comment.