- Intro slide
- Hello, World Example
- Explain:
fn
declarationprintln
is a macro
- Format strings in
println!
println("Hello, {}!", world);
- also show
{:?}
- Move "world" into a local variable so we can change it
let name = "Rustacean"; println("Hello, {}!", name);
- Abstract into a helper fn
fn greet(name: String) { println("Hello, {}!", name); }
- What goes wrong?
- Explain
format!
, show how you can use same helpers - Explain
push_str
and mutable local variableslet mut name = format!("fellow "); name.push_str("Rustacean");
- Explain
- Call helper fn twice
- What goes wrong now?
- Explain:
- Ownership slides
- Borrowing slides
- Borrowing example
- Show that
&
and&mut
cannot overlap - Time-limited
- Show that
- For loops
- show that
s
has typeString
- show that
- Options and enums
- explain about
unwrap
and how it is risky - show
let x = None
and unwrap - modify to some other example, like Shape / Square / Circle
- explain about
- Sequential search
- 10 minutes, wonder about
- Parallel search
- note the
use
statement - let's look at these two curious clones:
- we'll start with
shopping_list
- type of
shopping_list
is in fact a reference - threads can't close over a reference
- try to remove the clone, see what happens
- type of
- what about
name
?name
is needed becausestore
is moved into
- we'll start with
- how do we parallelize?
- we have to start ALL the threads before we join ANY of them
- note the
- Shared memory exercise
- Afterwards:
- show how you can change so that we request an
Vec<ShoppingList>
instead of&Vec
, note that in general if you will consume data, it's best to take it by value, and let the owner clone if they must - note that this applies equally well when using channels,
and in fact a common pattern is to send an
Arc<T>
over a channel
- show how you can change so that we request an
- Afterwards: