X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/ab7f9b241429bd675b437d2437799de75d2f409b..9f9b301fd5e86ae4b8cf743f80a129e4addb3635:/src/part10.rs?ds=inline diff --git a/src/part10.rs b/src/part10.rs index 6fa8f1e..0c90369 100644 --- a/src/part10.rs +++ b/src/part10.rs @@ -81,7 +81,7 @@ impl BigInt { pub fn print_with_prefix(b: &BigInt, prefix: String) { //@ The syntax for closures is `|arg1, arg2, ...| code`. Notice that the closure can reference variables like `prefix` that it did not //@ take as argument - variables that happen to be present *outside* of the closure. We say that the closure *captures* - //@ variables. Rust will now automatically create a type (like `PrintWithStruct`) for the environment of the closure + //@ variables. Rust will now automatically create a type (like `PrintWithString`) for the environment of the closure //@ with fields for every captured variable, implement the closure trait for this type such that the action performed //@ is given by the code of the closure, and finally it will instantiate the environment type here at the definition site //@ of the closure and fill it appropriately. @@ -108,7 +108,7 @@ pub fn print_and_count(b: &BigInt) { //@ Rust provides a whole lot of methods on iterators that allow us to write pretty functional-style list manipulation. // 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) { +fn inc_print_threshold(v: &Vec, offset: i32, threshold: i32) { //@ `map` takes a closure that is applied to every element of the iterator. `filter` removes elements //@ from the iterator that do not pass the test given by the closure. //@