-// With this fresh knowledge, let us now refactor `vec_min`. First of all, we are doing a small change
-// to the type: `&Vec<i32>` denotes a *reference* to a `Vec<i32>`. You can think of this as a pointer
-// (in C terms): Arguments in Rust are passed *by value*, so we need to employ explicit references if
-// that's not what we want. References are per default immutable (like variables), a mutable reference
-// would be denoted `&mut Vec<i32>`.
-fn vec_min(v: &Vec<i32>) -> NumberOrNothing {
+// Let us now refactor `vec_min`.
+fn vec_min(v: Vec<i32>) -> NumberOrNothing {
+ // Remember that helper function `min_i32`? Rust allows us to define such helper functions *inside* other
+ // functions. This is just a matter of namespacing, the inner function has no access to the data of the outer
+ // one. Still, being able to nicely group functions can be very useful.
+ fn min_i32(a: i32, b: i32) -> i32 {
+ if a < b { a } else { b }
+ }
+