-// 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 {
+// It is even the case that blocks are expressions, evaluating to the last expression they contain.
+fn compute_stuff(x: i32) -> i32 {
+ let y = { let z = x*x; z + 14 };
+ y*y
+}
+
+// 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
+ //@ significantly increase readability.
+ fn min_i32(a: i32, b: i32) -> i32 {
+ if a < b { a } else { b } /*@*/
+ }
+