println!("1st int call for value defg: {}", expensive_str_result.value("defg"));
}
+fn test_iterators() {
+ let v1 = vec!["Hello", "good", "world"];
+ // implied default is .into_iter() which consumes v1
+ for s in v1.iter() {
+ println!("element: {}", s);
+ }
+ // can still use it now
+ println!("v1: {:?}", &v1);
+
+ // manual iteration
+ let mut v1_iter = v1.iter();
+ while let Some(e) = v1_iter.next() {
+ println!("while loop over iter: {}", e);
+ }
+
+ for l_element in v1.iter().filter(|x| x.contains('l')) {
+ println!("v1 element containing 'l': {}", l_element);
+ }
+
+ let v2 = vec![1, 2, 3];
+ let double_v2: Vec<_> = v2.iter().map(|x| x * 2).collect();
+ println!("doubled v2: {:?}", double_v2);
+
+ for i in v2.into_iter().map(|x| x * 3) {
+ println!("for loop triplicating v2: {}", i);
+ }
+
+ for i in Counter5::new() {
+ println!("Counter 5 value: {}", i);
+ }
+}
+
fn main() {
test_strings();
test_vectors();
test_files();
test_generics();
test_closures();
+ test_iterators();
}