in 10 mins
the new C++ ?
impossible in 10 min !
It's "new"
- was born in 2006 - Graydon Hoare
- 2009 ----------------------->
- 2010 announced
- 2012 alpha version
- 1.0 released in 2015 =>
- 1.15 February 2, 2017
- 1.29.2 October 10, 2018
- 1.30.0 October 25, 2018
most loved programming language in:
2016, 2017 and 2018
- StackOverflow Survey
Multiparadigm
- Imperative
- Structured
- Functional
- Concurrent
- Generic
- Compiled
fn function (i: i32) -> i32 { i + 1 }
let closure_annotated = |i: i32| -> i32 { i + 1 };
let closure_inferred = |i | i + 1 ;
Control flexibility | |||
Double free | |||
Dangling pointers | |||
Buffer overflow | |||
Data races |
Comparison among other languages
Static Strong Typing
Inference
All variables are immutable by default
let elem = 5u8; //annotated as u8 type
let mut vec = Vec::new(); //growable array of something
vec.push(elem); // compiler knows now => Vec<u8>
Who's using it
- Amazon - Building tools in Rust.
- Atlassian - Using Rust in the backend.
- Dropbox - Using Rust in both the FE/BE.
- Facebook - Tools for source control.
- Google - As part of the Fuchsia project.
- Microsoft - Using Rust in part of their new Azure IoT work.
- npm - Using Rust in some of the npm core services.
- Red Hat - Creating a new storage system
- Reddit - Using Rust in its comment processing
- Twitter - As part of the build team support for Twitter.
-
Good abstraction
-
Memory safety ~ No GC
-
Good concurrency Handling
What provides Rust
Memory vulnerabilities
- One owner per value
- Assignments move ownership
- Value is freed automatically when owner returns
Memory safety in Rust
fn main() {
let name = String::new();
save(name);
save(name); // Error: name was moved
}
fn save(name: String) {
// this is taking ownership
// then frees memory allocated for 'name'
}
shared
- Others can read
- No writers
- Locks till it goes out of scope
mutable
- No other readers or writers
- Locks till it goes out of scope
when a reference is
Never have reader and writer at the same time
All is checked at compile time
fn main() {
let immutable_box = Box::new(5u32);
println!("immutable_box is {}", immutable_box); // 5
// *Move* the box (change the ownership)
// (and mutability)
let mut mutable_box = immutable_box;
// error! it's not owner
// println!("immutable_box is {}", immutable_box);
println!("mutable_box is {}", mutable_box); // 5
*mutable_box = 4;
println!("mutable_box now is {}", mutable_box); // 4
}
example
Good Abstraction
// Example 1
enum Event {
Load,
KeyPress(char),
Click { x: i64, y: i64 }
}
fn print_event(event: Event) {
match event {
Event::Load => println!("Loaded"),
Event::KeyPress(c) => println!("Key {} pressed", c),
Event::Click {x, y} => println!("Clicked at x={}, y={}", x, y),
}
}
// Example 2
fn load_images(paths: &[PathBuf]) -> Vec<Image> {
paths.iter()
.map(|path| Image::load(path))
.collect()
}
// Example 3
fn main() {
struct Dot { x: (u32, u32), y: u32 }
let dot = Dot { x: (1, 2), y: 3 };
let Dot { x: (a, b), y } = dot;
println!("a: {}, b: {}, y: {} ", a, b, y);
}
Generics
Traits
Closures
High order Functions
Macros
Builtins
Unit Tests
Fast code
Cross-lang interoparation
Lifetimes
Rust does not allow both at the same time
and verifies it
at compile time
Concurrency
Use cases
- WebAssembly (Wasm)
- Microcontrollers & IoT
- Low level
- Operating Systems
- Browsers
- Servers
- Tooling
- ... more
Tooling
|
|
---|---|
rustup | nvm |
cargo | npm |
rustfmt clippy |
~eslint |
Rust Playground | node REPL |
Adoption
Last
1..1_000 thanks
Rust Intro in 10 min
By Oswaldo Herrera
Rust Intro in 10 min
What is this multi paradigm programming language which emphasize control, safety and speed at the same time and that no other language have them? - Rust is a systems programming language that runs blazingly fast, prevents segfaults, and guarantees thread safety
- 523