X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/4f61be32dd480f23a7fef05ee66c42ae27c980c6..7fdd4203f19f2fa9096d0a662acf22d447e57af1:/src/part01.rs?ds=inline diff --git a/src/part01.rs b/src/part01.rs index ed4f73f..e73da23 100644 --- a/src/part01.rs +++ b/src/part01.rs @@ -35,6 +35,12 @@ fn number_or_default(n: NumberOrNothing, default: i32) -> i32 { } } +// 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) -> NumberOrNothing { //@ Remember that helper function `min_i32`? Rust allows us to define such helper functions *inside* other