projects
/
rust-101.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
tell mobile devices that we are prepared
[rust-101.git]
/
src
/
part01.rs
diff --git
a/src/part01.rs
b/src/part01.rs
index 11e9077d5ef326b7ee9be9b6d5e4c00fd6042419..7d29c49400e2f83f643532f812ea1b73045c2ea9 100644
(file)
--- 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<i32>) -> NumberOrNothing {
//@ Remember that helper function `min_i32`? Rust allows us to define such helper functions *inside* other
// 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
@@
-100,4
+106,4
@@
pub fn main() {
// **Exercise 01.2**: Write a function `vec_print` that takes a vector and prints all its elements.
// **Exercise 01.2**: Write a function `vec_print` that takes a vector and prints all its elements.
-//
[index](main.html) | [previous](part00.html
) | [next](part02.html)
+//
@ [index](main.html) | [previous](part00.html) | [raw source](https://www.ralfj.de/git/rust-101.git/blob_plain/HEAD:/workspace/src/part01.rs
) | [next](part02.html)