X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/63b7a79069a399c32d575bb71832fcad134117c9..4b4215163da009c2ad3941cc147a3598429e40f2:/src/part10.rs diff --git a/src/part10.rs b/src/part10.rs index b586cd5..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. //@ @@ -141,4 +141,4 @@ fn filter_vec_by_divisor(v: &Vec, divisor: i32) -> Vec { // product of those numbers that sit at odd positions? A function that checks whether a vector contains a certain number? Whether all numbers are // smaller than some threshold? Be creative! -//@ [index](main.html) | [previous](part09.html) | [raw source](https://www.ralfj.de/git/rust-101.git/blob_plain/HEAD:/workspace/src/part10.rs) | [next](part11.html) +//@ [index](main.html) | [previous](part09.html) | [raw source](workspace/src/part10.rs) | [next](part11.html)