//@ For example, consider `sqr`:
fn sqr(i: i32) -> i32 { i * i }
//@ Between the curly braces, we are giving the *expression* that computes the return value.
-//@ So we can just write `i * i`, the expression that returns the square if `i`!
+//@ So we can just write `i * i`, the expression that returns the square of `i`!
//@ This is very close to how mathematicians write down functions (but with more types).
// Conditionals are also just expressions. This is comparable to the ternary `? :` operator
//@ I/O is a complicated topic, so the code to do that is not exactly pretty - but well,
//@ let's get that behind us.
-// I/O is provided by the module `std::io`, so we first have import that with `use`.
+// I/O is provided by the module `std::io`, so we first have to import that with `use`.
// We also import the I/O *prelude*, which makes a bunch of commonly used I/O stuff
// directly available.
use std::io::prelude::*;
}
}
- // We can convert any vector of digits into a number, by removing trailing zeros. The `mut`
+ // Any vector of digits, which meets the structure of BigInt's `data` field, can be easily
+ // converted into a big number just by removing trailing zeros. The `mut`
// declaration for `v` here is just like the one in `let mut ...`: We completely own `v`, but Rust
// still asks us to make our intention of modifying it explicit. This `mut` is *not* part of the
// type of `from_vec` - the caller has to give up ownership of `v` anyway, so they don't care anymore
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.
// **Exercise 11.1**: We made the arbitrary choice of using `i32` for the arguments. Generalize the data structures above
// to work with an arbitrary type `T` that's passed to the callbacks. Since you need to call multiple callbacks with the
-// same `t: T`, you will either have to restrict `T` to `Copy` types, or pass a reference.
+// same `val: T` (in our `call` function), you will either have to restrict `T` to `Copy` types, or pass a reference.
//@ [index](main.html) | [previous](part10.html) | [raw source](workspace/src/part11.rs) | [next](part12.html)