summaryrefslogtreecommitdiff
path: root/meap/meap-code/ch2/ch2-simple-with-enumerate.rs
blob: d43bf5352850ae1c8c8e69e41b21c73c84a3bd35 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
fn main() {
  let search_term = "picture";
  let quote = "Every face, every shop, bedroom window, public-house, and
dark square is a picture feverishly turned--in search of what?
It is the same with books. What do we seek through millions of pages?";

  for (idx, line) in quote.lines().enumerate() {
    if line.contains(search_term) {
      let line_num = idx + 1;
      println!("{}: {}", line_num, line); // <2>
    }
  }
}