Agenda
Agenda
My experience with Rust
Introduc on to Rust
Why Rust
Slide 3
Slide 3 text
My experience
My experience
Embedded programming
STM32F3 Microcontroller
Some work in my day job
h ps:/
/crates.io/crates/credstash
Slide 4
Slide 4 text
Rust
Rust
Slide 5
Slide 5 text
Heap and Stack
Heap and Stack
Heap: Memory set aside for dynamic alloca on.
Stack: Memory set aside for a thread.
Slide 6
Slide 6 text
Ownership rules
Ownership rules
Each value in Rust has a variable that’s called its
owner.
There can only be one owner at a me.
When the owner goes out of scope, the value will
be dropped.
{
let s1 = String::from("hello ilugc"); // s1 is valid from
this point forward
// do stuff with s1
Slide 7
Slide 7 text
} // this scope is now over,
and s1 is no
// longer valid
Slide 8
Slide 8 text
Data interaction
Data interaction
fn main() {
let x: i32 = 5;
let y = x;
println!("Output: {} {}", x, y);
}
fn main() {
let x = String::from("hello ilugc");
let y = x;
println!("Output: {} {}", x, y);
}
Slide 9
Slide 9 text
Ownership
Ownership
fn main() {
let s = String::from("hello"); // s comes into scope
takes_ownership(s); // s's value moves into the
function...
// ... and so is no longer
valid here
let x = 5; // x comes into scope
makes_copy(x); // x would move into the
function,
// but i32 is Copy, so it’s
okay to still
// use x afterward
Slide 10
Slide 10 text
References
References
fn main() {
let s1 = String::from("hello");
let len = calculate_length(&s1);
println!("The length of '{}' is {}.", s1, len);
}
fn calculate_length(s: &String) -> usize {
s.len()
}