X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/9f6c55ebcab2e1d3073e8bb6c8c910d0116efee4..8fcdbed310c53f621fba0401399659ed1a1ec446:/src/part06.rs diff --git a/src/part06.rs b/src/part06.rs index 5b90142..6d50c2d 100644 --- a/src/part06.rs +++ b/src/part06.rs @@ -26,9 +26,9 @@ impl BigInt { } // 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) -> Option { let mut min: Option = None; + // If `v` is a shared borrowed vector, then the default for iterating over it is to call `iter`, the iterator that borrows the elements. for e in v { let e = e.clone(); /*@*/ min = Some(match min { /*@*/ @@ -38,7 +38,7 @@ fn vec_min(v: &Vec) -> Option { } min } -//@ Now, what's happening here? Why do we have to clone `e`, and why did we not +//@ Now, what's happening here? Why do we have to to make a full (deep) copy of `e`, and why did we not //@ have to do that in our previous version? //@ //@ The answer is already hidden in the type of `vec_min`: `v` is just borrowed, but