-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
53 lines (42 loc) · 1.17 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
fn iterator_example() {
let lines_of_code: Vec<String> = [
"MAIN:".to_string(),
"STORE #d 887.0".to_string(),
"STORE #e 888.0".to_string(),
"ADD #d #e".to_string(),
"PRINT #d".to_string(),
]
.to_vec();
let results_of_search: Vec<usize> = lines_of_code
.iter()
.enumerate()
.filter(|&(_, content)| content == "MAIN:")
.map(|(i, _)| i)
.collect();
println!("Result {:?}",results_of_search);
}
fn procedural_example() {
let lines_of_code: Vec<String> = [
"MAIN:".to_string(),
"STORE #d 887.0".to_string(),
"STORE #e 888.0".to_string(),
"ADD #d #e".to_string(),
"PRINT #d".to_string(),
]
.to_vec();
let mut line_counter = 0;
let mut results_of_search: Vec<usize> = Vec::new();
for line in lines_of_code.iter() {
match line.find("MAIN:") {
Some(_) => results_of_search.push(line_counter),
None => (),
}
line_counter += 1;
}
println!("Result {:?}",results_of_search);
}
fn main() {
println!("Hello, world!");
iterator_example();
procedural_example();
}