Skip to content

Commit ba92a7b

Browse files
committed
work
1 parent a48ef03 commit ba92a7b

13 files changed

+116
-8
lines changed

index.html

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<h2>Rust concurrency tutorial</h2>
2+
3+
<ol>
4+
<li> <a href="http://is.gd/MvBmlc">Hello World</a>
5+
<li> <b href="http://is.gd/jsTBs9">Borrowing</a> -- convert this code to use borrowing
6+
instead so that it compiles
7+
8+
</ol>

lesson-plan.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
- Intro slide
2+
- Hello, World Example
3+
- Explain:
4+
- `fn` declaration
5+
- `println` is a macro
6+
- Format strings in `println!`
7+
- `println("Hello, {}!", world);`
8+
- also show `{:?}`
9+
- Move "world" into a local variable so we can change it
10+
- `let name = "Rustacean"; println("Hello, {}!", name);`
11+
- Abstract into a helper fn
12+
- `fn greet(name: String) { println("Hello, {}!", name); }`
13+
- What goes wrong?
14+
- Explain `format!`, show how you can use same helpers
15+
- Explain `push_str` and mutable local variables
16+
- `let mut name = format!("fellow "); name.push_str("Rustacean");`
17+
- Call helper fn twice
18+
- What goes wrong now?
19+
- Ownership slides
20+
- Borrowing slides
21+
- Borrowing example
22+
- Show that `&` and `&mut` cannot overlap
23+
- Time-limited
24+
- For loops
25+
- show that `s` has type `String`

src/example00.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn main() {
2+
println!("Hello, world!");
3+
}

src/example01.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
pub fn main() {
2+
let name = format!("fellow Rustacean");
3+
helper(name);
4+
}
5+
6+
fn helper(name: String) {
7+
println!("Hello, {}!", name);
8+
}
9+
10+
// Discuss:
11+
// - &'static str vs String
12+
// - lead to

src/example02.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub fn main() {
2+
let mut name = format!("fellow ");
3+
name.push_str("Rustacean");
4+
helper(name);
5+
}
6+
7+
fn helper(name: String) {
8+
println!("Hello, {}!", name);
9+
}

src/example03.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
pub fn main() {
2+
let mut name = format!("fellow ");
3+
name.push_str("Rustacean");
4+
helper(&name);
5+
helper(&name);
6+
}
7+
8+
fn helper(name: &String) {
9+
println!("Hello, {}!", name);
10+
}

src/example04.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
pub fn main() {
2+
let mut name = format!("fellow ");
3+
adjust(&mut name);
4+
helper(&name);
5+
helper(&name);
6+
}
7+
8+
fn adjust(name: &mut String) {
9+
name.push_str("Rustacean");
10+
}
11+
12+
fn helper(name: &String) {
13+
println!("Hello, {}!", name);
14+
}

src/example05.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
pub fn main() {
2+
let mut name = Rc::new(format!("fellow "));
3+
helper(name.clone());
4+
helper(name.clone());
5+
}
6+
7+
fn helper(name: Rc<String>) {
8+
println!("Hello, {}!", name);
9+
}

src/example0.rs renamed to src/example10.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,8 @@ fn build_stores() -> Vec<Store> {
4949

5050
fn find_best_store(stores: Vec<Store>, shopping_list: &Vec<String>) -> String {
5151
// EXERCISE 0
52+
//
53+
// Find the store with the best price and return its name.
5254
assert!(stores.len() > 0);
5355
let mut best = None;
5456
let mut best_price = INFINITY;
File renamed without changes.

0 commit comments

Comments
 (0)