X-Git-Url: https://git.ralfj.de/rust-101.git/blobdiff_plain/4f61be32dd480f23a7fef05ee66c42ae27c980c6..cfc6a4901346f45284dcf591375f759e7193d561:/workspace/src/part01.rs?ds=sidebyside diff --git a/workspace/src/part01.rs b/workspace/src/part01.rs index 0578c43..ed6717c 100644 --- a/workspace/src/part01.rs +++ b/workspace/src/part01.rs @@ -1,5 +1,3 @@ -// ***Remember to enable/add this part in `main.rs`!*** - // Rust-101, Part 01: Expressions, Inherent methods // ================================================ @@ -26,6 +24,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 { fn min_i32(a: i32, b: i32) -> i32 {