X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/83e8dbfff2a6fdce785af58dbb13f007c4234cf2..e3b3bde6ba4c44e6a53deb791bea681014b3ecab:/workspace/src/part10.rs?ds=sidebyside diff --git a/workspace/src/part10.rs b/workspace/src/part10.rs index 9fd7642..c955394 100644 --- a/workspace/src/part10.rs +++ b/workspace/src/part10.rs @@ -1,8 +1,7 @@ // Rust-101, Part 10: Closures // =========================== -use std::io::prelude::*; -use std::{fmt,io}; +use std::fmt; use part05::BigInt; @@ -15,7 +14,7 @@ trait Action { impl BigInt { fn act_v1(&self, mut a: A) { for digit in self { - a.do_action(digit); + unimplemented!() } } } @@ -25,10 +24,10 @@ struct PrintWithString { } impl Action for PrintWithString { - // Here we perform performs the actual printing of the prefix and the digit. We're not making use of our ability to + // Here we perform the actual printing of the prefix and the digit. We're not making use of our ability to // change `self` here, but we could replace the prefix if we wanted. fn do_action(&mut self, digit: u64) { - println!("{}{}", self.prefix, digit); + unimplemented!() } } @@ -52,7 +51,7 @@ impl BigInt { fn act(&self, mut a: A) { for digit in self { // We can call closures as if they were functions - but really, what's happening here is translated to essentially what we wrote above, in `act_v1`. - a(digit); + unimplemented!() } } } @@ -76,7 +75,7 @@ pub fn print_and_count(b: &BigInt) { // Let's say we want to write a function that increments every entry of a `Vec` by some number, then looks for numbers larger than some threshold, and prints them. fn inc_print_even(v: &Vec, offset: i32, threshold: i32) { - for i in v.iter().map(|n| n + offset).filter(|n| *n > threshold) { + for i in v.iter().map(|n| *n + offset).filter(|n| *n > threshold) { println!("{}", i); } } @@ -90,7 +89,7 @@ fn print_enumerated(v: &Vec) { // And as a final example, one can also collect all elements of an iterator, and put them, e.g., in a vector. fn filter_vec_by_divisor(v: &Vec, divisor: i32) -> Vec { - v.iter().filter(|n| *n % divisor == 0).collect() + unimplemented!() } // **Exercise 10.1**: Look up the [documentation of `Iterator`](http://doc.rust-lang.org/stable/std/iter/trait.Iterator.html) to learn about more functions