//@ immutable per default, and you need to tell Rust if you want
//@ to change a variable later.
- // Now we want to *iterate* over the list. Rust has some nice syntax for
- // iterators:
+ // Now we want to *iterate* over the list. Rust has some nice syntax for iterators:
for el in vec {
// So `el` is al element of the list. We need to update `min` accordingly, but how do we get the current
// number in there? This is what pattern matching can do:
//@ details.)
for line in stdin.lock().lines() {
// Rust's type for (dynamic, growable) strings is `String`. However, our variable `line`
- // here is not yet of that type: It rather has type `io::Result<String>`.
- //@ The problem with I/O is that it can always go wrong. The type of `line`is a lot like `Option<String>` ("a `String` or
+ // here is not yet of that type: It has type `io::Result<String>`.
+ //@ The problem with I/O is that it can always go wrong. The type of `line` is a lot like `Option<String>` ("a `String` or
//@ nothing"), but in the case of "nothing", there is additional information about the error.
//@ Again, I recommend to check [the documentation](http://doc.rust-lang.org/stable/std/io/type.Result.html).
//@ You will see that `io::Result` is actually just an alias for `Result`, so click on that to obtain
}
}
-// Now we can write `vec_min`. However, in order to make it type-check, we have to make a full (deep) copy of e
-// by calling `clone()`.
+// Now we can write `vec_min`.
+//@ However, in order to make it type-check, we have to make a full (deep) copy of e by calling `clone()`.
fn vec_min(v: &Vec<BigInt>) -> Option<BigInt> {
let mut min: Option<BigInt> = None;
for e in v {
fn vec_min(vec: Vec<i32>) -> NumberOrNothing {
let mut min = NumberOrNothing::Nothing;
- // Now we want to *iterate* over the list. Rust has some nice syntax for
- // iterators:
+ // Now we want to *iterate* over the list. Rust has some nice syntax for iterators:
for el in vec {
// So `el` is al element of the list. We need to update `min` accordingly, but how do we get the current
// number in there? This is what pattern matching can do:
println!("Enter a list of numbers, one per line. End with Ctrl-D.");
for line in stdin.lock().lines() {
// Rust's type for (dynamic, growable) strings is `String`. However, our variable `line`
- // here is not yet of that type: It rather has type `io::Result<String>`.
+ // here is not yet of that type: It has type `io::Result<String>`.
// I chose the same name (`line`) for the new variable to ensure that I will never, accidentally,
// access the "old" `line` again.
}
}
-// Now we can write `vec_min`. However, in order to make it type-check, we have to make a full (deep) copy of e
-// by calling `clone()`.
+// Now we can write `vec_min`.
fn vec_min(v: &Vec<BigInt>) -> Option<BigInt> {
let mut min: Option<BigInt> = None;
for e in v {