More code.
Change-Id: Ie53ea58b3d0e8e906a2e51752ecfbe1e434b4261
diff --git a/src/bin/tut1.rs b/src/bin/tut1.rs
new file mode 100644
index 0000000..83596ad
--- /dev/null
+++ b/src/bin/tut1.rs
@@ -0,0 +1,43 @@
+// Structs, Borrowing
+
+#![allow(dead_code)]
+
+use rust_tutorial::*;
+
+fn greet_person_1(p: Person) {
+ println!("Hello {} ({})!", p.name, p.age);
+}
+
+fn greet_person_2(p: &Person) {
+ println!("Hello {} ({})!", p.name, p.age);
+}
+
+fn birthday(p: &mut Person) {
+ p.age += 1;
+}
+
+fn main() {
+ // -- Struct instantiation --
+ let mut p = Person {
+ age: 30,
+ name: "Mary".to_string(),
+ };
+
+ // -- Borrowing --
+ //greet_person_1(p);
+ //greet_person_1(p);
+
+ greet_person_2(&p);
+ greet_person_2(&p);
+
+ birthday(&mut p);
+
+ greet_person_2(&p);
+
+ // -- Traits --
+ println!("p = {}", p.to_string());
+
+ // -- Debugging --
+ let x = dbg!(100 + 2) + 3;
+ println!("Hello, world! 100 + 2 + 3 = {}", x);
+}
diff --git a/src/bin/tut2.rs b/src/bin/tut2.rs
new file mode 100644
index 0000000..702b870
--- /dev/null
+++ b/src/bin/tut2.rs
@@ -0,0 +1,42 @@
+#![allow(dead_code)]
+#![allow(unused_imports)]
+
+use rust_tutorial::*;
+
+/// Run this to see the disassembly of `compute_sum_of_squares_{1,2}`:
+///
+/// ```bash
+/// cargo objdump --bin tut2 --release -- -d | awk -v RS= '/^tut2::compute_sum_of_squares/'
+/// ```
+
+#[inline(never)]
+fn compute_sum_of_squares_1(xs: &Vec<i32>) -> i32 {
+ let mut acc = 0;
+ for x in xs {
+ acc += x * x;
+ }
+ acc
+}
+
+#[inline(never)]
+fn compute_sum_of_squares_2(xs: &Vec<i32>) -> i32 {
+ xs.iter()
+ .map(|x| x * x)
+ .fold(0, |acc, x| acc + x)
+}
+
+#[test]
+fn test_compute_sum_of_squares() {
+ let numbers = vec![1, 2, 3, 4, 5];
+ assert_eq!(compute_sum_of_squares_1(&numbers), compute_sum_of_squares_2(&numbers));
+}
+
+fn main() {
+ let numbers = vec![1, 2, 3, 4, 5];
+
+ let sum_of_squares_1 = compute_sum_of_squares_1(&numbers);
+ let sum_of_squares_2 = compute_sum_of_squares_2(&numbers);
+
+ println!("sum #1 = {}", sum_of_squares_1);
+ println!("sum #2 = {}", sum_of_squares_2);
+}
diff --git a/src/bin/tut3.rs b/src/bin/tut3.rs
new file mode 100644
index 0000000..a1005a0
--- /dev/null
+++ b/src/bin/tut3.rs
@@ -0,0 +1,39 @@
+// Generic Programming
+
+#![allow(dead_code)]
+#![allow(unused_imports)]
+
+use rust_tutorial::*;
+
+/// Run this to see the disassembly of `compute_sum_of_squares_{1,2}`:
+///
+/// ```bash
+/// cargo objdump --bin tut2 --release -- -d | awk -v RS= '/^tut2::compute_sum_of_squares/'
+/// ```
+
+#[inline(never)]
+fn compute_sum_of_squares_i32(zero: i32, xs: &Vec<i32>) -> i32 {
+ xs[1..].iter()
+ .map(|x| x * x)
+ .fold(zero, |acc, x| acc + x)
+}
+
+#[inline(never)]
+fn compute_sum_of_squares<T>(zero: T, xs: &Vec<T>) -> T
+where
+ T: std::ops::Mul<Output=T> + std::ops::Add<Output=T> + Copy
+{
+ xs[1..].iter()
+ .map(|x| *x * *x)
+ .fold(zero, |acc, x| acc + x)
+}
+
+fn main() {
+ let numbers = vec![1, 2, 3, 4, 5];
+
+ let sum_of_squares_i32 = compute_sum_of_squares_i32(0, &numbers);
+ let sum_of_squares_t = compute_sum_of_squares(0, &numbers);
+
+ println!("sum i32 = {}", sum_of_squares_i32);
+ println!("sum T = {}", sum_of_squares_t);
+}
diff --git a/src/bin/tut4.rs b/src/bin/tut4.rs
new file mode 100644
index 0000000..f743435
--- /dev/null
+++ b/src/bin/tut4.rs
@@ -0,0 +1,9 @@
+// Fearless Concurrency
+
+#![allow(dead_code)]
+#![allow(unused_imports)]
+
+use rust_tutorial::*;
+
+fn main() {
+}