SlideShare a Scribd company logo
1 of 116
Rust: Systems
Programming for
Everyone
Felix Klock (@pnkfelix), Mozilla
space : next slide; esc : overview; arrows navigate
http://bit.ly/1LQM
InfoQ.com: News & Community Site
• 750,000 unique visitors/month
• Published in 4 languages (English, Chinese, Japanese and Brazilian
Portuguese)
• Post content from our QCon conferences
• News 15-20 / week
• Articles 3-4 / week
• Presentations (videos) 12-15 / week
• Interviews 2-3 / week
• Books 1 / month
Watch the video with slide
synchronization on InfoQ.com!
https://www.infoq.com/presentations/
rust
Purpose of QCon
- to empower software development by facilitating the spread of
knowledge and innovation
Strategy
- practitioner-driven conference designed for YOU: influencers of
change and innovation in your teams
- speakers and topics driving the evolution and innovation
- connecting and catalyzing the influencers and innovators
Highlights
- attended by more than 12,000 delegates since 2007
- held in 9 cities worldwide
Presented at QCon London
www.qconlondon.com
Why ...?
Why use Rust?
Fast code, low memory footprint
Go from bare metal (assembly; C FFI) ...
... to high-level (collections, closures, generic
containers) ...
with zero cost (no GC, unboxed closures,
monomorphization of generics)
Safety and Parallelism
Safety and Parallelism
Safety
No segmentation faults
No undefined behavior
No data races
(Multi-paradigm) Parallelism
msg passing via channels
shared state via Arcand atomics, Mutex, etc
use native threads... or scoped threads... or work-stealing...
Why would you (Felix) work
on Rust?
It's awesome!
(Were prior slides really not a sufficient answer?)
oh, maybe you meant ...
Why would Mozilla sponsor Rust?
Hard to prototype research-y browser changes atop C++ code base
Rust ⇒Servo, WebRender
Want Rust for next-gen infrastructure (services, IoT)
"Our mission is to ensure the Internet is a global
public resource, open and accessible to all. An
Internet that truly puts people first, where
individuals can shape their own experience and are
empowered, safe and independent."
"accessible to all"
Where is Rust now?
1.0 release was back in May 2015
Rolling release cycle (up to Rust 1.7 as of March 2nd 2016)
Open source from the begining
https://github.com/rust-lang/rust/
Open model for future change (RFC process)
https://github.com/rust-lang/rfcs/
Awesome developer community (~1,000 people in #rust, ~250
people in #rust-internals, ~1,300 unique commiters to rust.git)
Talk plan
"Why Rust" Demonstration
"Ownership is easy" (... or is it?)
Sharing Stuff
Sharing capabilities (Language stuff)
Sharing work (Parallelism stuff)
Sharing code (Open source distribution stuff)
Lightning Demo
Demo: sequential web page fetch
fn sequential_web_fetch() {
use hyper::{self, Client};
use std::io::Read; // pulls in `chars` method
let sites = &["http://www.eff.org/", "http://rust-lang.org/",
"http://imgur.com", "http://mozilla.org"];
for &site in sites { // step through the array...
let client = Client::new();
let res = client.get(site).send().unwrap();
assert_eq!(res.status, hyper::Ok);
let char_count = res.chars().count();
println!("site: {} chars: {}", site, char_count);
}
}
(lets get rid of the Rust-specific pattern binding in for; this is not a
tutorial)
Demo: sequential web page fetch
fn sequential_web_fetch() {
use hyper::{self, Client};
use std::io::Read; // pulls in `chars` method
let sites = &["http://www.eff.org/", "http://rust-lang.org/",
"http://imgur.com", "http://mozilla.org"];
for site_ref in sites { // step through the array...
let site = *site_ref; // (separated for expository purposes)
{ // (and a separate block, again for expository purposes)
let client = Client::new();
let res = client.get(site).send().unwrap();
assert_eq!(res.status, hyper::Ok);
let char_count = res.chars().count();
println!("site: {} chars: {}", site, char_count);
}
}
}
Demo: concurrent web page fetch
fn concurrent_web_fetch() -> Vec<::std::thread::JoinHandle<()>> {
use hyper::{self, Client};
use std::io::Read; // pulls in `chars` method
let sites = &["http://www.eff.org/", "http://rust-lang.org/",
"http://imgur.com", "http://mozilla.org"];
let mut handles = Vec::new();
for site_ref in sites {
let site = *site_ref;
let handle = ::std::thread::spawn(move || {
// block code put in closure: ~~~~~~~
let client = Client::new();
let res = client.get(site).send().unwrap();
assert_eq!(res.status, hyper::Ok);
let char_count = res.chars().count();
println!("site: {} chars: {}", site, char_count);
});
handles.push(handle);
}
return handles;
}
Print outs
Sequential version:
site: http://www.eff.org/ chars: 42425
site: http://rust-lang.org/ chars: 16748
site: http://imgur.com chars: 152384
site: http://mozilla.org chars: 63349
(on every run, when internet, and sites, available)
Concurrent version:
site: http://imgur.com chars: 152384
site: http://rust-lang.org/ chars: 16748
site: http://mozilla.org chars: 63349
site: http://www.eff.org/ chars: 42425
(on at least one run)
"what is this 'soundness' of which
you speak?"
Demo: soundness I
fn sequential_web_fetch_2() {
use hyper::{self, Client};
use std::io::Read; // pulls in `chars` method
let sites = &["http://www.eff.org/", "http://rust-lang.org/",
// ~~~~~ `sites`, an array (slice) of strings, is stack-local
"http://imgur.com", "http://mozilla.org"];
for site_ref in sites {
// ~~~~~~~~ `site_ref` is a *reference to* elem of array.
let client = Client::new();
let res = client.get(*site_ref).send().unwrap();
// moved deref here ~~~~~~~~~
assert_eq!(res.status, hyper::Ok);
let char_count = res.chars().count();
println!("site: {} chars: {}", site_ref, char_count);
}
}
Demo: soundness II
fn concurrent_web_fetch_2() -> Vec<::std::thread::JoinHandle<()>> {
use hyper::{self, Client};
use std::io::Read; // pulls in `chars` method
let sites = &["http://www.eff.org/", "http://rust-lang.org/",
// ~~~~~ `sites`, an array (slice) of strings, is stack-local
"http://imgur.com", "http://mozilla.org"];
let mut handles = Vec::new();
for site_ref in sites {
// ~~~~~~~~ `site_ref` still a *reference* into an array
let handle = ::std::thread::spawn(move || {
let client = Client::new();
let res = client.get(*site_ref).send().unwrap();
// moved deref here ~~~~~~~~~
assert_eq!(res.status, hyper::Ok);
let char_count = res.chars().count();
println!("site: {} chars: {}", site_ref, char_count);
// Q: will `sites` array still be around when above runs?
});
handles.push(handle);
}
return handles;
}
some (white) lies:
"Rust is just about
ownership"
"Ownership is
intuitive"
"Ownership is intuitive"
Let's buy a car
let money: Money = bank.withdraw_cash();
let my_new_car: Car = dealership.buy_car(money);
let second_car = dealership.buy_car(money); // <-- cannot reuse
money transferred into dealership, and car transferred to us.
"Ownership is intuitive"
Let's buy a car
let money: Money = bank.withdraw_cash();
let my_new_car: Car = dealership.buy_car(money);
// let second_car = dealership.buy_car(money); // <-- cannot reuse
money transferred into dealership, and car transferred to us.
my_new_car.drive_to(home);
garage.park(my_new_car);
my_new_car.drive_to(...) // now doesn't work
(can't drive car without access to it, e.g. taking it out of the garage)
"Ownership is intuitive"
Let's buy a car
let money: Money = bank.withdraw_cash();
let my_new_car: Car = dealership.buy_car(money);
// let second_car = dealership.buy_car(money); // <-- cannot reuse
money transferred into dealership, and car transferred to us.
my_new_car.drive_to(home);
garage.park(my_new_car);
// my_new_car.drive_to(...) // now doesn't work
(can't drive car without access to it, e.g. taking it out of the garage)
let my_car = garage.unpark();
my_car.drive_to(work);
...reflection time...
Correction: Ownership is intuitive,
except for programmers ...
(copying data like integers, and characters, and .mp3's, is "free")
... and anyone else who names things
Über Sinn und Bedeutung
("On sense and reference" -- Gottlob Frege, 1892)
If ownership were all we had, car-purchase slide seems nonsensical
my_new_car.drive_to(home);
Does this transfer homeinto the car?
Do I lose access to my home, just because I drive to it?
We must distinguish an object itself from ways to name that object
Above, homecannot be (an owned) Home
homemust instead be some kind of reference to a Home
So we will need references
We can solve any problem by introducing an extra
level of indirection
-- David J. Wheeler
a truth: Ownership is important
Ownership is important
Ownership enables: which removes:
RAII-style destructors a source of memory leaks (or fd leaks, etc)
no dangling pointers many resource management bugs
no data races many multithreading heisenbugs
Do I need to take ownership here, accepting the
associated resource management responsibility?
Would temporary access suffice?
Good developers ask this already!
Rust forces function signatures to encode the answers
(and they are checked by the compiler)
Sharing Data:
Ownership and
References
Rust types
Move Copy Copy if T:Copy
Vec<T>, String, ... i32, char, ... [T; n], (T1,T2,T3), ...
struct Car { color: Color, engine: Engine }
fn demo_ownership() {
let mut used_car: Car = Car { color: Color::Red,
engine: Engine::BrokenV8 };
let apartments = ApartmentBuilding::new();
references to data (&mut T, &T):
let my_home: &Home; // <-- an "immutable" borrow
let christine: &mut Car; // <-- a "mutable" borrow
my_home = &apartments[6]; // (read `mut` as "exclusive")
let neighbors_home = &apartments[5];
christine = &mut used_car;
christine.engine = Engine::VintageV8;
}
Why multiple &-reference types?
Distinguish exclusive access from shared access
Enables safe, parallel API's
A Metaphor
(reminder: metaphors
never work 100%)
let christine = Car::new();
This is "Christine"
pristine unborrowed car
(apologies to Stephen King)
let read_only_borrow = &christine;
single inspector (immutable borrow)
(apologies to Randall Munroe)
read_only_borrows[2] = &christine;
read_only_borrows[3] = &christine;
read_only_borrows[4] = &christine;
many inspectors (immutable borrows)
When inspectors are finished, we are left again with:
pristine unborrowed car
let mutable_borrow = &mut christine; // like taking keys ...
give_arnie(mutable_borrow); // ... and giving them to someone
driven car (mutably borrowed)
Can't mix the two in safe code!
Otherwise: (data) races!
read_only_borrows[2] = &christine;
let mutable_borrow = &mut christine;
read_only_borrows[3] = &christine;
// ⇒ CHAOS!
mixing mutable and immutable is illegal
Ownership T
Exclusive access &mut T ("mutable")
Shared access &T ("read-only")
Exclusive access
&mut: can I borrow the car?
fn borrow_the_car_1() {
let mut christine = Car::new();
{
let car_keys = &mut christine;
let arnie = invite_friend_over();
arnie.lend(car_keys);
} // end of scope for `arnie` and `car_keys`
christine.drive_to(work); // I still own the car!
}
But when her keys are elsewhere, I cannot drive christine!
fn borrow_the_car_2() {
let mut christine = Car::new();
{
let car_keys = &mut christine;
let arnie = invite_friend_over();
arnie.lend(car_keys);
christine.drive_to(work); // <-- compile error
} // end of scope for `arnie` and `car_keys`
}
Extending the metaphor
Possessing the keys, Arnie could take the car for a new paint job.
fn lend_1(arnie: &Arnie, k: &mut Car) { k.color = arnie.fav_color; }
Or lend keys to someone else (reborrowing) before paint job
fn lend_2(arnie: &Arnie, k: &mut Car) {
arnie.partner.lend(k); k.color = arnie.fav_color;
}
Owner loses capabilities attached to &mut-borrows only temporarily (*)
(*): "Car keys" return guaranteed by Rust; sadly, not by physical world
End of metaphor
(on to models)
Pointers, Smart and
Otherwise
(More pictures)
Stack allocation
let b = B::new();
stack allocation
let b = B::new();
let r1: &B = &b;
let r2: &B = &b;
stack allocation and immutable borrows
(bhas lost write capability)
let mut b = B::new();
let w: &mut B = &mut b;
stack allocation and mutable borrows
(bhas temporarily lost both read and write capabilities)
Heap allocation: Box<B>
let a = Box::new(B::new());
pristine boxed B
a(as owner) has both read and write capabilities
Immutably borrowing a box
let a = Box::new(B::new());
let r_of_box: &Box<B> = &a; // (not directly a ref of B)
let r1: &B = &*a;
let r2: &B = &a; // <-- coercion!
immutable borrows of heap-allocated B
aretains read capabilities (has temporarily lost write)
Mutably borrowing a box
let mut a = Box::new(B::new());
let w: &mut B = &mut a; // (again, coercion happening here)
mutable borrow of heap-allocated B
ahas temporarily lost both read and write capabilities
Heap allocation: Vec<B>
let mut a = Vec::new();
for i in 0..n { a.push(B::new()); }
vec, filled to capacity
Vec Reallocation
...
a.push(B::new());
before after
Slices: borrowing parts of an array
Basic Vec<B>
let mut a = Vec::new();
for i in 0..n { a.push(B::new()); }
pristine unborrowed vec
(ahas read and write capabilities)
Immutable borrowed slices
let mut a = Vec::new();
for i in 0..n { a.push(B::new()); }
let r1 = &a[0..3];
let r2 = &a[7..n-4];
mutiple borrowed slices vec
(ahas only read capability now; shares it with r1and r2)
Safe overlap between &[..]
let mut a = Vec::new();
for i in 0..n { a.push(B::new()); }
let r1 = &a[0..7];
let r2 = &a[3..n-4];
overlapping slices
Basic Vec<B>again
pristine unborrowed vec
(ahas read and write capabilities)
Mutable slice of whole vec
let w = &mut a[0..n];
mutable slice of vec
(ahas no capabilities; wnow has read and write capability)
Mutable disjoint slices
let (w1,w2) = a.split_at_mut(n-4);
disjoint mutable borrows
(w1and w2share read and write capabilities for disjoint portions)
Shared Ownership
Shared Ownership
let rc1 = Rc::new(B::new());
let rc2 = rc1.clone(); // increments ref-count on heap-alloc'd value
shared ownership via ref counting
(rc1and rc2each have read access; but neither can statically assume
exclusive (mut) access, nor can they provide &mutborrows without
assistance.)
Dynamic Exclusivity
RefCell<T>: Dynamic Exclusivity
let b = Box::new(RefCell::new(B::new()));
let r1: &RefCell<B> = &b;
let r2: &RefCell<B> = &b;
box of refcell
RefCell<T>: Dynamic Exclusivity
let b = Box::new(RefCell::new(B::new()));
let r1: &RefCell<B> = &b;
let r2: &RefCell<B> = &b;
let w = r2.borrow_mut(); // if successful, `w` acts like `&mut B`
fallible mutable borrow
// below panics if `w` still in scope
let w2 = b.borrow_mut();
Previous generalizes to
shared ownership
Rc<RefCell<T>>
let rc1 = Rc::new(RefCell::new(B::new()));
let rc2 = rc1.clone(); // increments ref-count on heap-alloc'd value
shared ownership of refcell
Rc<RefCell<T>>
let rc1 = Rc::new(RefCell::new(B::new()));
let rc2 = rc1.clone();
let r1: &RefCell<B> = &rc1;
let r2: &RefCell<B> = &rc2; // (or even just `r1`)
borrows of refcell can alias
Rc<RefCell<T>>
let rc1 = Rc::new(RefCell::new(B::new()));
let rc2 = rc1.clone();
let w = rc2.borrow_mut();
there can be only one!
What static guarantees does
Rc<RefCell<T>>have?
Not much!
If you want to port an existing imperative algorithm with all sorts of
sharing, you could try using Rc<RefCell<T>>.
You then might spend much less time wrestling with Rust's type
(+borrow) checker.
The point: Rc<RefCell<T>>is nearly an anti-pattern. It limits static
reasoning. You should avoid it if you can.
Other kinds of shared ownership
TypedArena<T>
Cow<T>
Rc<T>vs Arc<T>
Sharing Work:
Parallelism /
Concurrency
Threading APIs (plural!)
std::thread
dispatch: OS X-specific "Grand Central Dispatch"
crossbeam: Lock-Free Abstractions, Scoped "Must-be" Concurrency
rayon: Scoped Fork-join "Maybe" Parallelism (inspired by Cilk)
(Only the first comes with Rust out of the box)
std::thread
fn concurrent_web_fetch() -> Vec<::std::thread::JoinHandle<()>> {
use hyper::{self, Client};
use std::io::Read; // pulls in `chars` method
let sites = &["http://www.eff.org/", "http://rust-lang.org/",
"http://imgur.com", "http://mozilla.org"];
let mut handles = Vec::new();
for site_ref in sites {
let site = *site_ref;
let handle = ::std::thread::spawn(move || {
// block code put in closure: ~~~~~~~
let client = Client::new();
let res = client.get(site).send().unwrap();
assert_eq!(res.status, hyper::Ok);
let char_count = res.chars().count();
println!("site: {} chars: {}", site, char_count);
});
handles.push(handle);
}
return handles;
}
dispatch
fn concurrent_gcd_fetch() -> Vec<::dispatch::Queue> {
use hyper::{self, Client};
use std::io::Read; // pulls in `chars` method
use dispatch::{Queue, QueueAttribute};
let sites = &["http://www.eff.org/", "http://rust-lang.org/",
"http://imgur.com", "http://mozilla.org"];
let mut queues = Vec::new();
for site_ref in sites {
let site = *site_ref;
let q = Queue::create("qcon2016", QueueAttribute::Serial);
q.async(move || {
let client = Client::new();
let res = client.get(site).send().unwrap();
assert_eq!(res.status, hyper::Ok);
let char_count = res.chars().count();
println!("site: {} chars: {}", site, char_count);
});
queues.push(q);
}
return queues;
}
crossbeam
lock-free data structures
scoped threading abstraction
upholds Rust's safety (data-race freedom)
guarantees
lock-free data structures
crossbeamMPSC benchmark
mean ns/msg (2 producers, 1 consumer; msg count 10e6; 1G heap)
Rust
channel
crossbeam
MSQ
crossbeam
SegQueue
Scala
MSQ
Java
ConcurrentLinkedQue
108ns 98ns
53ns
461ns
192ns
crossbeamMPMC benchmark
mean ns/msg (2 producers, 2 consumers; msg count 10e6; 1G heap)
Rust
channel
(N/A)
crossbeam
MSQ
crossbeam
SegQueue
Scala
MSQ
Java
ConcurrentLinkedQue
102ns
58ns
239ns
204ns
See "Lock-freedom without garbage collection"
https://aturon.github.io/blog/2015/08/27/epoch/
scoped threading?
std::theaddoes not allow sharing stack-local data
fn std_thread_fail() {
let array: [u32; 3] = [1, 2, 3];
for i in &array {
::std::thread::spawn(|| {
println!("element: {}", i);
});
}
}
error: `array` does not live long enough
crossbeamscoped threading
fn crossbeam_demo() {
let array = [1, 2, 3];
::crossbeam::scope(|scope| {
for i in &array {
scope.spawn(move || {
println!("element: {}", i);
});
}
});
}
::crossbeam::scopeenforces parent thread joins on all spawned
children before returning
ensures that it is sound for children to access local references
passed into them.
crossbeam scope: "must-
be concurrency"
Each scope.spawn(..)invocation fires up a fresh
thread
(Literally just a wrapper around std::thread)
rayon: "maybe
parallelism"
rayondemo 1: map reduce
Sequential
fn demo_map_reduce_seq(stores: &[Store], list: Groceries) -> u32 {
let total_price = stores.iter()
.map(|store| store.compute_price(&list))
.sum();
return total_price;
}
Parallel (potentially)
fn demo_map_reduce_par(stores: &[Store], list: Groceries) -> u32 {
let total_price = stores.par_iter()
.map(|store| store.compute_price(&list))
.sum();
return total_price;
}
Rayon's Rule
the decision of whether or not to use parallel threads
is made dynamically, based on whether idle cores
are available
i.e., solely for offloading work, not for when concurrent operation is
necessary for correctness
(uses work-stealing under the hood to distribute work among a fixed
set of threads)
rayondemo 2: quicksort
fn quick_sort<T:PartialOrd+Send>(v: &mut [T]) {
if v.len() > 1 {
let mid = partition(v);
let (lo, hi) = v.split_at_mut(mid);
rayon::join(|| quick_sort(lo),
|| quick_sort(hi));
}
}
fn partition<T:PartialOrd+Send>(v: &mut [T]) -> usize {
// see https://en.wikipedia.org/wiki/
// Quicksort#Lomuto_partition_scheme
...
}
rayondemo 3: buggy quicksort
fn quick_sort<T:PartialOrd+Send>(v: &mut [T]) {
if v.len() > 1 {
let mid = partition(v);
let (lo, hi) = v.split_at_mut(mid);
rayon::join(|| quick_sort(lo),
|| quick_sort(hi));
}
}
fn quick_sort<T:PartialOrd+Send>(v: &mut [T]) {
if v.len() > 1 {
let mid = partition(v);
let (lo, hi) = v.split_at_mut(mid);
rayon::join(|| quick_sort(lo),
|| quick_sort(lo));
// ~~ data race!
}
}
(See blog post "Rayon: Data Parallelism in Rust" bit.ly/1IZcku4)
Big Idea
3rd parties identify (and provide) new abstractions for
concurrency and parallelism unanticipated in std lib.
Soundness and 3rd
Party Concurrency
The Secret Sauce
Send
Sync
lifetime bounds
Send and Sync
T: Sendmeans an instance of Tcan be transferred between threads
(i.e. move or copied as appropriate)
T: Syncmeans two threads can safely share a reference to an
instance of T
Examples
T: Send: Tcan be transferred between threads
T: Sync: two threads can share refs to a T
Stringis Send
Vec<T>is Send(if Tis Send)
(double-check: why not require T: Syncfor Vec<T>: Send?)
Rc<T>is not Send(for any T)
but Arc<T>is Send(if Tis Sendand Sync)
(to ponder: why require T:Sendfor Arc<T>?)
&Tis Sendif T: Sync
&mut Tis Sendif T: Send
Send and Sync are only
half the story
other half is lifetime bounds; come
see me if curious
Sharing Code:
Cargo
Sharing Code
std::threadis provided with std lib
But dispatch, crossbeam, and rayonare 3rd party
(not to mention hyperand a host of other crates used in this talk's
construction)
What is Rust's code distribution story?
Cargo
cargois really simple to use
cargo new -- create a project
cargo test -- run project's unit tests
cargo run -- run binaries associated with project
cargo publish -- push project up to crates.io
Edit the associated Cargo.tomlfile to:
add dependencies
specify version / licensing info
conditionally compiled features
add build-time behaviors (e.g. code generation)
"What's this about crates.io?"
crates.io
Open-source crate distribution site
Has every version of every crate
Cargo adheres to semver
Semver
The use of in cargobasically amounts to this:Semantic Versioning
Major versions (MAJOR.minor.patch) are free to break whatever they
want.
New public API's can be added with minor versions updates
(major.MINOR.patch), as long as they do not impose breaking changes.
In Rust, breaking changes includes data-structure representation
changes.
Adding fields to structs (or variants to enums) can cause their memory
representation to change.
Why major versions can include
breaking changes
Cargo invokes the Rust compiler in a way that salts the symbols
exported by a compiled library.
This ends up allowing two distinct (major) versions of a library to be
used simultaneously in the same program.
This is important when pulling in third party libraries.
Fixing versions
cargogenerates a Cargo.lockfile that tracks the versions you built
the project with
Intent: application (i.e. final) crates should check their Cargo.lock
into version control
Ensures that future build attempts will choose the same versions
However: library (i.e. intermediate) crates should not check their
Cargo.lockinto version control.
Instead, everyone should follow sem.ver.; then individual applications
can mix different libraries into their final product, upgrading
intermediate libraries as necessary
Crate dependency graph
Compiler ensures one cannot pass struct defined via Xversion 2.x.y
into function expecting Xversion 1.m.n, or vice versa.
A: Graph Structure B: Token API
C: Lexical Scanner D: GLL Parser P: Linked Program
In Practice
If you (*) follow the sem.ver. rules, then you do not usually have to
think hard about those sorts of pictures.
"you" is really "you and all the crates you use"
 
You may not believe me, but cargois really simple to use
Coming from a C/C++ world, this feels like magic
(probably feels like old hat for people used to package dependency
managers)
Final Words
Final Words
(and no more pictures)
Interop
Rust to C
easy: extern { ... }and unsafe { ... }
C to Rust
easy: #[no_mangle] extern "C" fn foo(...) { ... }
Ruby, Python, etc to Rust
see e.g. https://github.com/wycats/rust-bridge
Customers
Mozilla (of course)
Skylight
MaidSafe
... others
Pivot from C/C++ to Rust
Maidsafe is one example of this
Rust as enabler of
individuals
From "mere script programmer"
to "lauded systems hacker"
Or if you prefer:
Enabling sharing systems hacking knowledge with
everyone
Programming in Rust has made me
look at C++ code in a whole new light
Thanks
www.rust-lang.org
Hack Without Fear
Watch the video with slide synchronization on
InfoQ.com!
https://www.infoq.com/presentations/rust

More Related Content

What's hot

An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...Claudio Capobianco
 
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016Codemotion
 
Introduction to Rust language programming
Introduction to Rust language programmingIntroduction to Rust language programming
Introduction to Rust language programmingRodolfo Finochietti
 
Introduction to rust: a low-level language with high-level abstractions
Introduction to rust: a low-level language with high-level abstractionsIntroduction to rust: a low-level language with high-level abstractions
Introduction to rust: a low-level language with high-level abstractionsyann_s
 
Guaranteeing Memory Safety in Rust
Guaranteeing Memory Safety in RustGuaranteeing Memory Safety in Rust
Guaranteeing Memory Safety in Rustnikomatsakis
 
Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017Roman Elizarov
 
Memory safety in rust
Memory safety in rustMemory safety in rust
Memory safety in rustJawahar
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)Brendan Gregg
 
XDP in Practice: DDoS Mitigation @Cloudflare
XDP in Practice: DDoS Mitigation @CloudflareXDP in Practice: DDoS Mitigation @Cloudflare
XDP in Practice: DDoS Mitigation @CloudflareC4Media
 
Introduction to haskell
Introduction to haskellIntroduction to haskell
Introduction to haskellLuca Molteni
 
XSS Magic tricks
XSS Magic tricksXSS Magic tricks
XSS Magic tricksGarethHeyes
 
Domain Modeling with FP (DDD Europe 2020)
Domain Modeling with FP (DDD Europe 2020)Domain Modeling with FP (DDD Europe 2020)
Domain Modeling with FP (DDD Europe 2020)Scott Wlaschin
 
Implementing the IO Monad in Scala
Implementing the IO Monad in ScalaImplementing the IO Monad in Scala
Implementing the IO Monad in ScalaHermann Hueck
 
Deep dive in Docker Overlay Networks
Deep dive in Docker Overlay NetworksDeep dive in Docker Overlay Networks
Deep dive in Docker Overlay NetworksLaurent Bernaille
 

What's hot (20)

Rust vs C++
Rust vs C++Rust vs C++
Rust vs C++
 
Rust-lang
Rust-langRust-lang
Rust-lang
 
An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...An introduction to Rust: the modern programming language to develop safe and ...
An introduction to Rust: the modern programming language to develop safe and ...
 
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016
 
Introduction to Rust language programming
Introduction to Rust language programmingIntroduction to Rust language programming
Introduction to Rust language programming
 
Rust
RustRust
Rust
 
Introduction to rust: a low-level language with high-level abstractions
Introduction to rust: a low-level language with high-level abstractionsIntroduction to rust: a low-level language with high-level abstractions
Introduction to rust: a low-level language with high-level abstractions
 
The Rust Programming Language
The Rust Programming LanguageThe Rust Programming Language
The Rust Programming Language
 
Rust
RustRust
Rust
 
Rust Primer
Rust PrimerRust Primer
Rust Primer
 
Guaranteeing Memory Safety in Rust
Guaranteeing Memory Safety in RustGuaranteeing Memory Safety in Rust
Guaranteeing Memory Safety in Rust
 
Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017Deep dive into Coroutines on JVM @ KotlinConf 2017
Deep dive into Coroutines on JVM @ KotlinConf 2017
 
Memory safety in rust
Memory safety in rustMemory safety in rust
Memory safety in rust
 
BPF Internals (eBPF)
BPF Internals (eBPF)BPF Internals (eBPF)
BPF Internals (eBPF)
 
XDP in Practice: DDoS Mitigation @Cloudflare
XDP in Practice: DDoS Mitigation @CloudflareXDP in Practice: DDoS Mitigation @Cloudflare
XDP in Practice: DDoS Mitigation @Cloudflare
 
Introduction to haskell
Introduction to haskellIntroduction to haskell
Introduction to haskell
 
XSS Magic tricks
XSS Magic tricksXSS Magic tricks
XSS Magic tricks
 
Domain Modeling with FP (DDD Europe 2020)
Domain Modeling with FP (DDD Europe 2020)Domain Modeling with FP (DDD Europe 2020)
Domain Modeling with FP (DDD Europe 2020)
 
Implementing the IO Monad in Scala
Implementing the IO Monad in ScalaImplementing the IO Monad in Scala
Implementing the IO Monad in Scala
 
Deep dive in Docker Overlay Networks
Deep dive in Docker Overlay NetworksDeep dive in Docker Overlay Networks
Deep dive in Docker Overlay Networks
 

Viewers also liked

Embedded Rust on IoT devices
Embedded Rust on IoT devicesEmbedded Rust on IoT devices
Embedded Rust on IoT devicesLars Gregori
 
Embedded Rust – Rust on IoT devices
Embedded Rust – Rust on IoT devicesEmbedded Rust – Rust on IoT devices
Embedded Rust – Rust on IoT devicesLars Gregori
 
JavaScript and Internet Controlled Electronics
JavaScript and Internet Controlled ElectronicsJavaScript and Internet Controlled Electronics
JavaScript and Internet Controlled ElectronicsJonathan LeBlanc
 
Programming The Arduino Due in Rust
Programming The Arduino Due in RustProgramming The Arduino Due in Rust
Programming The Arduino Due in Rustkellogh
 
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOMERuby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOMEJulien Fitzpatrick
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 pramode_ce
 
Unba.se – San Diego Rust – march 2017 (abridged)
Unba.se – San Diego Rust – march 2017 (abridged)Unba.se – San Diego Rust – march 2017 (abridged)
Unba.se – San Diego Rust – march 2017 (abridged)Daniel Norman
 
Presentatie remco van wijk
Presentatie remco van wijkPresentatie remco van wijk
Presentatie remco van wijkVisma | PinkWeb
 
Internet of things, lafayette tech
Internet of things, lafayette techInternet of things, lafayette tech
Internet of things, lafayette techkellogh
 
Let's Play STM32
Let's Play STM32Let's Play STM32
Let's Play STM32Jay Chen
 
Servo: The parallel web engine
Servo: The parallel web engineServo: The parallel web engine
Servo: The parallel web engineBruno Abinader
 
Stm32 f4 first touch
Stm32 f4 first touchStm32 f4 first touch
Stm32 f4 first touchBenux Wei
 
Mozilla + Rust at PCU Manila 02 DEC 2016
Mozilla + Rust at PCU Manila 02 DEC 2016Mozilla + Rust at PCU Manila 02 DEC 2016
Mozilla + Rust at PCU Manila 02 DEC 2016Robert 'Bob' Reyes
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011Patrick Walton
 
Introduction to Rust Programming Language
Introduction to Rust Programming LanguageIntroduction to Rust Programming Language
Introduction to Rust Programming LanguageRobert 'Bob' Reyes
 
unba.se - ACM CSCW 2017 - IWCES15
unba.se - ACM CSCW 2017 - IWCES15unba.se - ACM CSCW 2017 - IWCES15
unba.se - ACM CSCW 2017 - IWCES15Daniel Norman
 
Track 2 session 2 - st dev con 2016 - stm32 open development environment
Track 2   session 2 - st dev con 2016 - stm32 open development  environmentTrack 2   session 2 - st dev con 2016 - stm32 open development  environment
Track 2 session 2 - st dev con 2016 - stm32 open development environmentST_World
 
Performance Comparison of Mutex, RWLock and Atomic types in Rust
Performance Comparison of Mutex, RWLock and  Atomic types in RustPerformance Comparison of Mutex, RWLock and  Atomic types in Rust
Performance Comparison of Mutex, RWLock and Atomic types in RustMitsunori Komatsu
 

Viewers also liked (20)

Embedded Rust on IoT devices
Embedded Rust on IoT devicesEmbedded Rust on IoT devices
Embedded Rust on IoT devices
 
Embedded Rust – Rust on IoT devices
Embedded Rust – Rust on IoT devicesEmbedded Rust – Rust on IoT devices
Embedded Rust – Rust on IoT devices
 
JavaScript and Internet Controlled Electronics
JavaScript and Internet Controlled ElectronicsJavaScript and Internet Controlled Electronics
JavaScript and Internet Controlled Electronics
 
Programming The Arduino Due in Rust
Programming The Arduino Due in RustProgramming The Arduino Due in Rust
Programming The Arduino Due in Rust
 
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOMERuby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
Ruby is Awesome and Rust is Awesome and Building a Game in Both is AWESOME
 
Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017 Rust Workshop - NITC FOSSMEET 2017
Rust Workshop - NITC FOSSMEET 2017
 
Unba.se – San Diego Rust – march 2017 (abridged)
Unba.se – San Diego Rust – march 2017 (abridged)Unba.se – San Diego Rust – march 2017 (abridged)
Unba.se – San Diego Rust – march 2017 (abridged)
 
Presentatie remco van wijk
Presentatie remco van wijkPresentatie remco van wijk
Presentatie remco van wijk
 
Internet of things, lafayette tech
Internet of things, lafayette techInternet of things, lafayette tech
Internet of things, lafayette tech
 
Let's Play STM32
Let's Play STM32Let's Play STM32
Let's Play STM32
 
Servo: The parallel web engine
Servo: The parallel web engineServo: The parallel web engine
Servo: The parallel web engine
 
Stm32 f4 first touch
Stm32 f4 first touchStm32 f4 first touch
Stm32 f4 first touch
 
Mozilla + Rust at PCU Manila 02 DEC 2016
Mozilla + Rust at PCU Manila 02 DEC 2016Mozilla + Rust at PCU Manila 02 DEC 2016
Mozilla + Rust at PCU Manila 02 DEC 2016
 
Rust All Hands Winter 2011
Rust All Hands Winter 2011Rust All Hands Winter 2011
Rust All Hands Winter 2011
 
présentation STM32
présentation STM32présentation STM32
présentation STM32
 
Introduction to stm32-part1
Introduction to stm32-part1Introduction to stm32-part1
Introduction to stm32-part1
 
Introduction to Rust Programming Language
Introduction to Rust Programming LanguageIntroduction to Rust Programming Language
Introduction to Rust Programming Language
 
unba.se - ACM CSCW 2017 - IWCES15
unba.se - ACM CSCW 2017 - IWCES15unba.se - ACM CSCW 2017 - IWCES15
unba.se - ACM CSCW 2017 - IWCES15
 
Track 2 session 2 - st dev con 2016 - stm32 open development environment
Track 2   session 2 - st dev con 2016 - stm32 open development  environmentTrack 2   session 2 - st dev con 2016 - stm32 open development  environment
Track 2 session 2 - st dev con 2016 - stm32 open development environment
 
Performance Comparison of Mutex, RWLock and Atomic types in Rust
Performance Comparison of Mutex, RWLock and  Atomic types in RustPerformance Comparison of Mutex, RWLock and  Atomic types in Rust
Performance Comparison of Mutex, RWLock and Atomic types in Rust
 

Similar to Rust: Systems Programming for Everyone

Rails missing features
Rails missing featuresRails missing features
Rails missing featuresAstrails
 
Codemotion 2012 Rome - An OpenShift Primer
Codemotion 2012 Rome - An OpenShift PrimerCodemotion 2012 Rome - An OpenShift Primer
Codemotion 2012 Rome - An OpenShift PrimerEric D. Schabell
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backendDavid Padbury
 
Container (Docker) Orchestration Tools
Container (Docker) Orchestration ToolsContainer (Docker) Orchestration Tools
Container (Docker) Orchestration ToolsDhilipsiva DS
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkAarti Parikh
 
Docker and containers - For Boston Docker Meetup Workshop in March 2015
Docker and containers - For Boston Docker Meetup Workshop in March 2015Docker and containers - For Boston Docker Meetup Workshop in March 2015
Docker and containers - For Boston Docker Meetup Workshop in March 2015Jonas Rosland
 
Front-end. Global domination
Front-end. Global dominationFront-end. Global domination
Front-end. Global dominationStfalcon Meetups
 
Docker and Containers overview - Docker Workshop
Docker and Containers overview - Docker WorkshopDocker and Containers overview - Docker Workshop
Docker and Containers overview - Docker WorkshopJonas Rosland
 
AMIMOTO WordPress + Amazon Web Services for ALL Tech Levels
AMIMOTO WordPress + Amazon Web Services for ALL Tech Levels AMIMOTO WordPress + Amazon Web Services for ALL Tech Levels
AMIMOTO WordPress + Amazon Web Services for ALL Tech Levels Kel
 
Javascript - Getting started | DevCom ISITCom
Javascript - Getting started | DevCom ISITComJavascript - Getting started | DevCom ISITCom
Javascript - Getting started | DevCom ISITComHamdi Hmidi
 
Docker Training - June 2015
Docker Training - June 2015Docker Training - June 2015
Docker Training - June 2015{code}
 
Developing and Deploying PHP with Docker
Developing and Deploying PHP with DockerDeveloping and Deploying PHP with Docker
Developing and Deploying PHP with DockerPatrick Mizer
 
Testing API platform with Behat BDD tests
Testing API platform with Behat BDD testsTesting API platform with Behat BDD tests
Testing API platform with Behat BDD testsStefan Adolf
 
PyData Berlin Meetup
PyData Berlin MeetupPyData Berlin Meetup
PyData Berlin MeetupSteffen Wenz
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsRemy Sharp
 
POX to HATEOAS: Our Company's Journey Building a Hypermedia API
POX to HATEOAS: Our Company's Journey Building a Hypermedia APIPOX to HATEOAS: Our Company's Journey Building a Hypermedia API
POX to HATEOAS: Our Company's Journey Building a Hypermedia APILuke Stokes
 
2019 11-bgphp
2019 11-bgphp2019 11-bgphp
2019 11-bgphpdantleech
 
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Asher Martin
 

Similar to Rust: Systems Programming for Everyone (20)

Rails missing features
Rails missing featuresRails missing features
Rails missing features
 
Codemotion 2012 Rome - An OpenShift Primer
Codemotion 2012 Rome - An OpenShift PrimerCodemotion 2012 Rome - An OpenShift Primer
Codemotion 2012 Rome - An OpenShift Primer
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Container (Docker) Orchestration Tools
Container (Docker) Orchestration ToolsContainer (Docker) Orchestration Tools
Container (Docker) Orchestration Tools
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
 
Docker and containers - For Boston Docker Meetup Workshop in March 2015
Docker and containers - For Boston Docker Meetup Workshop in March 2015Docker and containers - For Boston Docker Meetup Workshop in March 2015
Docker and containers - For Boston Docker Meetup Workshop in March 2015
 
About Clack
About ClackAbout Clack
About Clack
 
Front-end. Global domination
Front-end. Global dominationFront-end. Global domination
Front-end. Global domination
 
Frontend. Global domination.
Frontend. Global domination.Frontend. Global domination.
Frontend. Global domination.
 
Docker and Containers overview - Docker Workshop
Docker and Containers overview - Docker WorkshopDocker and Containers overview - Docker Workshop
Docker and Containers overview - Docker Workshop
 
AMIMOTO WordPress + Amazon Web Services for ALL Tech Levels
AMIMOTO WordPress + Amazon Web Services for ALL Tech Levels AMIMOTO WordPress + Amazon Web Services for ALL Tech Levels
AMIMOTO WordPress + Amazon Web Services for ALL Tech Levels
 
Javascript - Getting started | DevCom ISITCom
Javascript - Getting started | DevCom ISITComJavascript - Getting started | DevCom ISITCom
Javascript - Getting started | DevCom ISITCom
 
Docker Training - June 2015
Docker Training - June 2015Docker Training - June 2015
Docker Training - June 2015
 
Developing and Deploying PHP with Docker
Developing and Deploying PHP with DockerDeveloping and Deploying PHP with Docker
Developing and Deploying PHP with Docker
 
Testing API platform with Behat BDD tests
Testing API platform with Behat BDD testsTesting API platform with Behat BDD tests
Testing API platform with Behat BDD tests
 
PyData Berlin Meetup
PyData Berlin MeetupPyData Berlin Meetup
PyData Berlin Meetup
 
HTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & socketsHTML5 tutorial: canvas, offfline & sockets
HTML5 tutorial: canvas, offfline & sockets
 
POX to HATEOAS: Our Company's Journey Building a Hypermedia API
POX to HATEOAS: Our Company's Journey Building a Hypermedia APIPOX to HATEOAS: Our Company's Journey Building a Hypermedia API
POX to HATEOAS: Our Company's Journey Building a Hypermedia API
 
2019 11-bgphp
2019 11-bgphp2019 11-bgphp
2019 11-bgphp
 
Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2Cape Cod Web Technology Meetup - 2
Cape Cod Web Technology Meetup - 2
 

More from C4Media

Streaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoStreaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoC4Media
 
Next Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileNext Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileC4Media
 
Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020C4Media
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsC4Media
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No KeeperC4Media
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like OwnersC4Media
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaC4Media
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideC4Media
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDC4Media
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine LearningC4Media
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at SpeedC4Media
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsC4Media
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsC4Media
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerC4Media
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleC4Media
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeC4Media
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereC4Media
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing ForC4Media
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data EngineeringC4Media
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreC4Media
 

More from C4Media (20)

Streaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live VideoStreaming a Million Likes/Second: Real-Time Interactions on Live Video
Streaming a Million Likes/Second: Real-Time Interactions on Live Video
 
Next Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy MobileNext Generation Client APIs in Envoy Mobile
Next Generation Client APIs in Envoy Mobile
 
Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020Software Teams and Teamwork Trends Report Q1 2020
Software Teams and Teamwork Trends Report Q1 2020
 
Understand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java ApplicationsUnderstand the Trade-offs Using Compilers for Java Applications
Understand the Trade-offs Using Compilers for Java Applications
 
Kafka Needs No Keeper
Kafka Needs No KeeperKafka Needs No Keeper
Kafka Needs No Keeper
 
High Performing Teams Act Like Owners
High Performing Teams Act Like OwnersHigh Performing Teams Act Like Owners
High Performing Teams Act Like Owners
 
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to JavaDoes Java Need Inline Types? What Project Valhalla Can Bring to Java
Does Java Need Inline Types? What Project Valhalla Can Bring to Java
 
Service Meshes- The Ultimate Guide
Service Meshes- The Ultimate GuideService Meshes- The Ultimate Guide
Service Meshes- The Ultimate Guide
 
Shifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CDShifting Left with Cloud Native CI/CD
Shifting Left with Cloud Native CI/CD
 
CI/CD for Machine Learning
CI/CD for Machine LearningCI/CD for Machine Learning
CI/CD for Machine Learning
 
Fault Tolerance at Speed
Fault Tolerance at SpeedFault Tolerance at Speed
Fault Tolerance at Speed
 
Architectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep SystemsArchitectures That Scale Deep - Regaining Control in Deep Systems
Architectures That Scale Deep - Regaining Control in Deep Systems
 
ML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.jsML in the Browser: Interactive Experiences with Tensorflow.js
ML in the Browser: Interactive Experiences with Tensorflow.js
 
Build Your Own WebAssembly Compiler
Build Your Own WebAssembly CompilerBuild Your Own WebAssembly Compiler
Build Your Own WebAssembly Compiler
 
User & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix ScaleUser & Device Identity for Microservices @ Netflix Scale
User & Device Identity for Microservices @ Netflix Scale
 
Scaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's EdgeScaling Patterns for Netflix's Edge
Scaling Patterns for Netflix's Edge
 
Make Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home EverywhereMake Your Electron App Feel at Home Everywhere
Make Your Electron App Feel at Home Everywhere
 
The Talk You've Been Await-ing For
The Talk You've Been Await-ing ForThe Talk You've Been Await-ing For
The Talk You've Been Await-ing For
 
Future of Data Engineering
Future of Data EngineeringFuture of Data Engineering
Future of Data Engineering
 
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and MoreAutomated Testing for Terraform, Docker, Packer, Kubernetes, and More
Automated Testing for Terraform, Docker, Packer, Kubernetes, and More
 

Recently uploaded

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Hyundai Motor Group
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsHyundai Motor Group
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxOnBoard
 

Recently uploaded (20)

SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2Next-generation AAM aircraft unveiled by Supernal, S-A2
Next-generation AAM aircraft unveiled by Supernal, S-A2
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter RoadsSnow Chain-Integrated Tire for a Safe Drive on Winter Roads
Snow Chain-Integrated Tire for a Safe Drive on Winter Roads
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
Maximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptxMaximizing Board Effectiveness 2024 Webinar.pptx
Maximizing Board Effectiveness 2024 Webinar.pptx
 

Rust: Systems Programming for Everyone

  • 1. Rust: Systems Programming for Everyone Felix Klock (@pnkfelix), Mozilla space : next slide; esc : overview; arrows navigate http://bit.ly/1LQM
  • 2. InfoQ.com: News & Community Site • 750,000 unique visitors/month • Published in 4 languages (English, Chinese, Japanese and Brazilian Portuguese) • Post content from our QCon conferences • News 15-20 / week • Articles 3-4 / week • Presentations (videos) 12-15 / week • Interviews 2-3 / week • Books 1 / month Watch the video with slide synchronization on InfoQ.com! https://www.infoq.com/presentations/ rust
  • 3. Purpose of QCon - to empower software development by facilitating the spread of knowledge and innovation Strategy - practitioner-driven conference designed for YOU: influencers of change and innovation in your teams - speakers and topics driving the evolution and innovation - connecting and catalyzing the influencers and innovators Highlights - attended by more than 12,000 delegates since 2007 - held in 9 cities worldwide Presented at QCon London www.qconlondon.com
  • 5. Why use Rust? Fast code, low memory footprint Go from bare metal (assembly; C FFI) ... ... to high-level (collections, closures, generic containers) ... with zero cost (no GC, unboxed closures, monomorphization of generics) Safety and Parallelism
  • 6. Safety and Parallelism Safety No segmentation faults No undefined behavior No data races (Multi-paradigm) Parallelism msg passing via channels shared state via Arcand atomics, Mutex, etc use native threads... or scoped threads... or work-stealing...
  • 7. Why would you (Felix) work on Rust? It's awesome! (Were prior slides really not a sufficient answer?) oh, maybe you meant ...
  • 8. Why would Mozilla sponsor Rust? Hard to prototype research-y browser changes atop C++ code base Rust ⇒Servo, WebRender Want Rust for next-gen infrastructure (services, IoT) "Our mission is to ensure the Internet is a global public resource, open and accessible to all. An Internet that truly puts people first, where individuals can shape their own experience and are empowered, safe and independent." "accessible to all"
  • 9. Where is Rust now? 1.0 release was back in May 2015 Rolling release cycle (up to Rust 1.7 as of March 2nd 2016) Open source from the begining https://github.com/rust-lang/rust/ Open model for future change (RFC process) https://github.com/rust-lang/rfcs/ Awesome developer community (~1,000 people in #rust, ~250 people in #rust-internals, ~1,300 unique commiters to rust.git)
  • 10. Talk plan "Why Rust" Demonstration "Ownership is easy" (... or is it?) Sharing Stuff Sharing capabilities (Language stuff) Sharing work (Parallelism stuff) Sharing code (Open source distribution stuff)
  • 12. Demo: sequential web page fetch fn sequential_web_fetch() { use hyper::{self, Client}; use std::io::Read; // pulls in `chars` method let sites = &["http://www.eff.org/", "http://rust-lang.org/", "http://imgur.com", "http://mozilla.org"]; for &site in sites { // step through the array... let client = Client::new(); let res = client.get(site).send().unwrap(); assert_eq!(res.status, hyper::Ok); let char_count = res.chars().count(); println!("site: {} chars: {}", site, char_count); } } (lets get rid of the Rust-specific pattern binding in for; this is not a tutorial)
  • 13. Demo: sequential web page fetch fn sequential_web_fetch() { use hyper::{self, Client}; use std::io::Read; // pulls in `chars` method let sites = &["http://www.eff.org/", "http://rust-lang.org/", "http://imgur.com", "http://mozilla.org"]; for site_ref in sites { // step through the array... let site = *site_ref; // (separated for expository purposes) { // (and a separate block, again for expository purposes) let client = Client::new(); let res = client.get(site).send().unwrap(); assert_eq!(res.status, hyper::Ok); let char_count = res.chars().count(); println!("site: {} chars: {}", site, char_count); } } }
  • 14. Demo: concurrent web page fetch fn concurrent_web_fetch() -> Vec<::std::thread::JoinHandle<()>> { use hyper::{self, Client}; use std::io::Read; // pulls in `chars` method let sites = &["http://www.eff.org/", "http://rust-lang.org/", "http://imgur.com", "http://mozilla.org"]; let mut handles = Vec::new(); for site_ref in sites { let site = *site_ref; let handle = ::std::thread::spawn(move || { // block code put in closure: ~~~~~~~ let client = Client::new(); let res = client.get(site).send().unwrap(); assert_eq!(res.status, hyper::Ok); let char_count = res.chars().count(); println!("site: {} chars: {}", site, char_count); }); handles.push(handle); } return handles; }
  • 15. Print outs Sequential version: site: http://www.eff.org/ chars: 42425 site: http://rust-lang.org/ chars: 16748 site: http://imgur.com chars: 152384 site: http://mozilla.org chars: 63349 (on every run, when internet, and sites, available) Concurrent version: site: http://imgur.com chars: 152384 site: http://rust-lang.org/ chars: 16748 site: http://mozilla.org chars: 63349 site: http://www.eff.org/ chars: 42425 (on at least one run)
  • 16. "what is this 'soundness' of which you speak?"
  • 17. Demo: soundness I fn sequential_web_fetch_2() { use hyper::{self, Client}; use std::io::Read; // pulls in `chars` method let sites = &["http://www.eff.org/", "http://rust-lang.org/", // ~~~~~ `sites`, an array (slice) of strings, is stack-local "http://imgur.com", "http://mozilla.org"]; for site_ref in sites { // ~~~~~~~~ `site_ref` is a *reference to* elem of array. let client = Client::new(); let res = client.get(*site_ref).send().unwrap(); // moved deref here ~~~~~~~~~ assert_eq!(res.status, hyper::Ok); let char_count = res.chars().count(); println!("site: {} chars: {}", site_ref, char_count); } }
  • 18. Demo: soundness II fn concurrent_web_fetch_2() -> Vec<::std::thread::JoinHandle<()>> { use hyper::{self, Client}; use std::io::Read; // pulls in `chars` method let sites = &["http://www.eff.org/", "http://rust-lang.org/", // ~~~~~ `sites`, an array (slice) of strings, is stack-local "http://imgur.com", "http://mozilla.org"]; let mut handles = Vec::new(); for site_ref in sites { // ~~~~~~~~ `site_ref` still a *reference* into an array let handle = ::std::thread::spawn(move || { let client = Client::new(); let res = client.get(*site_ref).send().unwrap(); // moved deref here ~~~~~~~~~ assert_eq!(res.status, hyper::Ok); let char_count = res.chars().count(); println!("site: {} chars: {}", site_ref, char_count); // Q: will `sites` array still be around when above runs? }); handles.push(handle); } return handles; }
  • 19. some (white) lies: "Rust is just about ownership"
  • 21. "Ownership is intuitive" Let's buy a car let money: Money = bank.withdraw_cash(); let my_new_car: Car = dealership.buy_car(money); let second_car = dealership.buy_car(money); // <-- cannot reuse money transferred into dealership, and car transferred to us.
  • 22. "Ownership is intuitive" Let's buy a car let money: Money = bank.withdraw_cash(); let my_new_car: Car = dealership.buy_car(money); // let second_car = dealership.buy_car(money); // <-- cannot reuse money transferred into dealership, and car transferred to us. my_new_car.drive_to(home); garage.park(my_new_car); my_new_car.drive_to(...) // now doesn't work (can't drive car without access to it, e.g. taking it out of the garage)
  • 23. "Ownership is intuitive" Let's buy a car let money: Money = bank.withdraw_cash(); let my_new_car: Car = dealership.buy_car(money); // let second_car = dealership.buy_car(money); // <-- cannot reuse money transferred into dealership, and car transferred to us. my_new_car.drive_to(home); garage.park(my_new_car); // my_new_car.drive_to(...) // now doesn't work (can't drive car without access to it, e.g. taking it out of the garage) let my_car = garage.unpark(); my_car.drive_to(work); ...reflection time...
  • 24. Correction: Ownership is intuitive, except for programmers ... (copying data like integers, and characters, and .mp3's, is "free") ... and anyone else who names things
  • 25. Über Sinn und Bedeutung ("On sense and reference" -- Gottlob Frege, 1892) If ownership were all we had, car-purchase slide seems nonsensical my_new_car.drive_to(home); Does this transfer homeinto the car? Do I lose access to my home, just because I drive to it? We must distinguish an object itself from ways to name that object Above, homecannot be (an owned) Home homemust instead be some kind of reference to a Home
  • 26. So we will need references We can solve any problem by introducing an extra level of indirection -- David J. Wheeler
  • 27. a truth: Ownership is important
  • 28. Ownership is important Ownership enables: which removes: RAII-style destructors a source of memory leaks (or fd leaks, etc) no dangling pointers many resource management bugs no data races many multithreading heisenbugs Do I need to take ownership here, accepting the associated resource management responsibility? Would temporary access suffice? Good developers ask this already! Rust forces function signatures to encode the answers (and they are checked by the compiler)
  • 30. Rust types Move Copy Copy if T:Copy Vec<T>, String, ... i32, char, ... [T; n], (T1,T2,T3), ... struct Car { color: Color, engine: Engine } fn demo_ownership() { let mut used_car: Car = Car { color: Color::Red, engine: Engine::BrokenV8 }; let apartments = ApartmentBuilding::new(); references to data (&mut T, &T): let my_home: &Home; // <-- an "immutable" borrow let christine: &mut Car; // <-- a "mutable" borrow my_home = &apartments[6]; // (read `mut` as "exclusive") let neighbors_home = &apartments[5]; christine = &mut used_car; christine.engine = Engine::VintageV8; }
  • 31. Why multiple &-reference types? Distinguish exclusive access from shared access Enables safe, parallel API's
  • 34. let christine = Car::new(); This is "Christine" pristine unborrowed car (apologies to Stephen King)
  • 35. let read_only_borrow = &christine; single inspector (immutable borrow) (apologies to Randall Munroe)
  • 36. read_only_borrows[2] = &christine; read_only_borrows[3] = &christine; read_only_borrows[4] = &christine; many inspectors (immutable borrows)
  • 37. When inspectors are finished, we are left again with: pristine unborrowed car
  • 38. let mutable_borrow = &mut christine; // like taking keys ... give_arnie(mutable_borrow); // ... and giving them to someone driven car (mutably borrowed)
  • 39. Can't mix the two in safe code! Otherwise: (data) races!
  • 40. read_only_borrows[2] = &christine; let mutable_borrow = &mut christine; read_only_borrows[3] = &christine; // ⇒ CHAOS! mixing mutable and immutable is illegal
  • 41. Ownership T Exclusive access &mut T ("mutable") Shared access &T ("read-only")
  • 43. &mut: can I borrow the car? fn borrow_the_car_1() { let mut christine = Car::new(); { let car_keys = &mut christine; let arnie = invite_friend_over(); arnie.lend(car_keys); } // end of scope for `arnie` and `car_keys` christine.drive_to(work); // I still own the car! } But when her keys are elsewhere, I cannot drive christine! fn borrow_the_car_2() { let mut christine = Car::new(); { let car_keys = &mut christine; let arnie = invite_friend_over(); arnie.lend(car_keys); christine.drive_to(work); // <-- compile error } // end of scope for `arnie` and `car_keys` }
  • 44. Extending the metaphor Possessing the keys, Arnie could take the car for a new paint job. fn lend_1(arnie: &Arnie, k: &mut Car) { k.color = arnie.fav_color; } Or lend keys to someone else (reborrowing) before paint job fn lend_2(arnie: &Arnie, k: &mut Car) { arnie.partner.lend(k); k.color = arnie.fav_color; } Owner loses capabilities attached to &mut-borrows only temporarily (*) (*): "Car keys" return guaranteed by Rust; sadly, not by physical world
  • 45. End of metaphor (on to models)
  • 48. Stack allocation let b = B::new(); stack allocation
  • 49. let b = B::new(); let r1: &B = &b; let r2: &B = &b; stack allocation and immutable borrows (bhas lost write capability)
  • 50. let mut b = B::new(); let w: &mut B = &mut b; stack allocation and mutable borrows (bhas temporarily lost both read and write capabilities)
  • 51. Heap allocation: Box<B> let a = Box::new(B::new()); pristine boxed B a(as owner) has both read and write capabilities
  • 52. Immutably borrowing a box let a = Box::new(B::new()); let r_of_box: &Box<B> = &a; // (not directly a ref of B) let r1: &B = &*a; let r2: &B = &a; // <-- coercion! immutable borrows of heap-allocated B aretains read capabilities (has temporarily lost write)
  • 53. Mutably borrowing a box let mut a = Box::new(B::new()); let w: &mut B = &mut a; // (again, coercion happening here) mutable borrow of heap-allocated B ahas temporarily lost both read and write capabilities
  • 54. Heap allocation: Vec<B> let mut a = Vec::new(); for i in 0..n { a.push(B::new()); }
  • 55. vec, filled to capacity
  • 57.
  • 58. Slices: borrowing parts of an array
  • 59. Basic Vec<B> let mut a = Vec::new(); for i in 0..n { a.push(B::new()); } pristine unborrowed vec (ahas read and write capabilities)
  • 60. Immutable borrowed slices let mut a = Vec::new(); for i in 0..n { a.push(B::new()); } let r1 = &a[0..3]; let r2 = &a[7..n-4]; mutiple borrowed slices vec (ahas only read capability now; shares it with r1and r2)
  • 61. Safe overlap between &[..] let mut a = Vec::new(); for i in 0..n { a.push(B::new()); } let r1 = &a[0..7]; let r2 = &a[3..n-4]; overlapping slices
  • 62. Basic Vec<B>again pristine unborrowed vec (ahas read and write capabilities)
  • 63. Mutable slice of whole vec let w = &mut a[0..n]; mutable slice of vec (ahas no capabilities; wnow has read and write capability)
  • 64. Mutable disjoint slices let (w1,w2) = a.split_at_mut(n-4); disjoint mutable borrows (w1and w2share read and write capabilities for disjoint portions)
  • 66. Shared Ownership let rc1 = Rc::new(B::new()); let rc2 = rc1.clone(); // increments ref-count on heap-alloc'd value shared ownership via ref counting (rc1and rc2each have read access; but neither can statically assume exclusive (mut) access, nor can they provide &mutborrows without assistance.)
  • 68. RefCell<T>: Dynamic Exclusivity let b = Box::new(RefCell::new(B::new())); let r1: &RefCell<B> = &b; let r2: &RefCell<B> = &b; box of refcell
  • 69. RefCell<T>: Dynamic Exclusivity let b = Box::new(RefCell::new(B::new())); let r1: &RefCell<B> = &b; let r2: &RefCell<B> = &b; let w = r2.borrow_mut(); // if successful, `w` acts like `&mut B` fallible mutable borrow
  • 70. // below panics if `w` still in scope let w2 = b.borrow_mut();
  • 72. Rc<RefCell<T>> let rc1 = Rc::new(RefCell::new(B::new())); let rc2 = rc1.clone(); // increments ref-count on heap-alloc'd value shared ownership of refcell
  • 73. Rc<RefCell<T>> let rc1 = Rc::new(RefCell::new(B::new())); let rc2 = rc1.clone(); let r1: &RefCell<B> = &rc1; let r2: &RefCell<B> = &rc2; // (or even just `r1`) borrows of refcell can alias
  • 74. Rc<RefCell<T>> let rc1 = Rc::new(RefCell::new(B::new())); let rc2 = rc1.clone(); let w = rc2.borrow_mut(); there can be only one!
  • 75. What static guarantees does Rc<RefCell<T>>have? Not much! If you want to port an existing imperative algorithm with all sorts of sharing, you could try using Rc<RefCell<T>>. You then might spend much less time wrestling with Rust's type (+borrow) checker. The point: Rc<RefCell<T>>is nearly an anti-pattern. It limits static reasoning. You should avoid it if you can.
  • 76. Other kinds of shared ownership TypedArena<T> Cow<T> Rc<T>vs Arc<T>
  • 78. Threading APIs (plural!) std::thread dispatch: OS X-specific "Grand Central Dispatch" crossbeam: Lock-Free Abstractions, Scoped "Must-be" Concurrency rayon: Scoped Fork-join "Maybe" Parallelism (inspired by Cilk) (Only the first comes with Rust out of the box)
  • 79. std::thread fn concurrent_web_fetch() -> Vec<::std::thread::JoinHandle<()>> { use hyper::{self, Client}; use std::io::Read; // pulls in `chars` method let sites = &["http://www.eff.org/", "http://rust-lang.org/", "http://imgur.com", "http://mozilla.org"]; let mut handles = Vec::new(); for site_ref in sites { let site = *site_ref; let handle = ::std::thread::spawn(move || { // block code put in closure: ~~~~~~~ let client = Client::new(); let res = client.get(site).send().unwrap(); assert_eq!(res.status, hyper::Ok); let char_count = res.chars().count(); println!("site: {} chars: {}", site, char_count); }); handles.push(handle); } return handles; }
  • 80. dispatch fn concurrent_gcd_fetch() -> Vec<::dispatch::Queue> { use hyper::{self, Client}; use std::io::Read; // pulls in `chars` method use dispatch::{Queue, QueueAttribute}; let sites = &["http://www.eff.org/", "http://rust-lang.org/", "http://imgur.com", "http://mozilla.org"]; let mut queues = Vec::new(); for site_ref in sites { let site = *site_ref; let q = Queue::create("qcon2016", QueueAttribute::Serial); q.async(move || { let client = Client::new(); let res = client.get(site).send().unwrap(); assert_eq!(res.status, hyper::Ok); let char_count = res.chars().count(); println!("site: {} chars: {}", site, char_count); }); queues.push(q); } return queues; }
  • 81. crossbeam lock-free data structures scoped threading abstraction upholds Rust's safety (data-race freedom) guarantees
  • 83. crossbeamMPSC benchmark mean ns/msg (2 producers, 1 consumer; msg count 10e6; 1G heap) Rust channel crossbeam MSQ crossbeam SegQueue Scala MSQ Java ConcurrentLinkedQue 108ns 98ns 53ns 461ns 192ns
  • 84. crossbeamMPMC benchmark mean ns/msg (2 producers, 2 consumers; msg count 10e6; 1G heap) Rust channel (N/A) crossbeam MSQ crossbeam SegQueue Scala MSQ Java ConcurrentLinkedQue 102ns 58ns 239ns 204ns See "Lock-freedom without garbage collection" https://aturon.github.io/blog/2015/08/27/epoch/
  • 85. scoped threading? std::theaddoes not allow sharing stack-local data fn std_thread_fail() { let array: [u32; 3] = [1, 2, 3]; for i in &array { ::std::thread::spawn(|| { println!("element: {}", i); }); } } error: `array` does not live long enough
  • 86. crossbeamscoped threading fn crossbeam_demo() { let array = [1, 2, 3]; ::crossbeam::scope(|scope| { for i in &array { scope.spawn(move || { println!("element: {}", i); }); } }); } ::crossbeam::scopeenforces parent thread joins on all spawned children before returning ensures that it is sound for children to access local references passed into them.
  • 87. crossbeam scope: "must- be concurrency" Each scope.spawn(..)invocation fires up a fresh thread (Literally just a wrapper around std::thread)
  • 89. rayondemo 1: map reduce Sequential fn demo_map_reduce_seq(stores: &[Store], list: Groceries) -> u32 { let total_price = stores.iter() .map(|store| store.compute_price(&list)) .sum(); return total_price; } Parallel (potentially) fn demo_map_reduce_par(stores: &[Store], list: Groceries) -> u32 { let total_price = stores.par_iter() .map(|store| store.compute_price(&list)) .sum(); return total_price; }
  • 90. Rayon's Rule the decision of whether or not to use parallel threads is made dynamically, based on whether idle cores are available i.e., solely for offloading work, not for when concurrent operation is necessary for correctness (uses work-stealing under the hood to distribute work among a fixed set of threads)
  • 91. rayondemo 2: quicksort fn quick_sort<T:PartialOrd+Send>(v: &mut [T]) { if v.len() > 1 { let mid = partition(v); let (lo, hi) = v.split_at_mut(mid); rayon::join(|| quick_sort(lo), || quick_sort(hi)); } } fn partition<T:PartialOrd+Send>(v: &mut [T]) -> usize { // see https://en.wikipedia.org/wiki/ // Quicksort#Lomuto_partition_scheme ... }
  • 92. rayondemo 3: buggy quicksort fn quick_sort<T:PartialOrd+Send>(v: &mut [T]) { if v.len() > 1 { let mid = partition(v); let (lo, hi) = v.split_at_mut(mid); rayon::join(|| quick_sort(lo), || quick_sort(hi)); } } fn quick_sort<T:PartialOrd+Send>(v: &mut [T]) { if v.len() > 1 { let mid = partition(v); let (lo, hi) = v.split_at_mut(mid); rayon::join(|| quick_sort(lo), || quick_sort(lo)); // ~~ data race! } } (See blog post "Rayon: Data Parallelism in Rust" bit.ly/1IZcku4)
  • 93. Big Idea 3rd parties identify (and provide) new abstractions for concurrency and parallelism unanticipated in std lib.
  • 94. Soundness and 3rd Party Concurrency
  • 96. Send and Sync T: Sendmeans an instance of Tcan be transferred between threads (i.e. move or copied as appropriate) T: Syncmeans two threads can safely share a reference to an instance of T
  • 97. Examples T: Send: Tcan be transferred between threads T: Sync: two threads can share refs to a T Stringis Send Vec<T>is Send(if Tis Send) (double-check: why not require T: Syncfor Vec<T>: Send?) Rc<T>is not Send(for any T) but Arc<T>is Send(if Tis Sendand Sync) (to ponder: why require T:Sendfor Arc<T>?) &Tis Sendif T: Sync &mut Tis Sendif T: Send
  • 98. Send and Sync are only half the story other half is lifetime bounds; come see me if curious
  • 100. Sharing Code std::threadis provided with std lib But dispatch, crossbeam, and rayonare 3rd party (not to mention hyperand a host of other crates used in this talk's construction) What is Rust's code distribution story?
  • 101. Cargo cargois really simple to use cargo new -- create a project cargo test -- run project's unit tests cargo run -- run binaries associated with project cargo publish -- push project up to crates.io Edit the associated Cargo.tomlfile to: add dependencies specify version / licensing info conditionally compiled features add build-time behaviors (e.g. code generation) "What's this about crates.io?"
  • 102. crates.io Open-source crate distribution site Has every version of every crate Cargo adheres to semver
  • 103. Semver The use of in cargobasically amounts to this:Semantic Versioning Major versions (MAJOR.minor.patch) are free to break whatever they want. New public API's can be added with minor versions updates (major.MINOR.patch), as long as they do not impose breaking changes. In Rust, breaking changes includes data-structure representation changes. Adding fields to structs (or variants to enums) can cause their memory representation to change.
  • 104. Why major versions can include breaking changes Cargo invokes the Rust compiler in a way that salts the symbols exported by a compiled library. This ends up allowing two distinct (major) versions of a library to be used simultaneously in the same program. This is important when pulling in third party libraries.
  • 105. Fixing versions cargogenerates a Cargo.lockfile that tracks the versions you built the project with Intent: application (i.e. final) crates should check their Cargo.lock into version control Ensures that future build attempts will choose the same versions However: library (i.e. intermediate) crates should not check their Cargo.lockinto version control. Instead, everyone should follow sem.ver.; then individual applications can mix different libraries into their final product, upgrading intermediate libraries as necessary
  • 106. Crate dependency graph Compiler ensures one cannot pass struct defined via Xversion 2.x.y into function expecting Xversion 1.m.n, or vice versa. A: Graph Structure B: Token API C: Lexical Scanner D: GLL Parser P: Linked Program
  • 107. In Practice If you (*) follow the sem.ver. rules, then you do not usually have to think hard about those sorts of pictures. "you" is really "you and all the crates you use"   You may not believe me, but cargois really simple to use Coming from a C/C++ world, this feels like magic (probably feels like old hat for people used to package dependency managers)
  • 109. Final Words (and no more pictures)
  • 110. Interop Rust to C easy: extern { ... }and unsafe { ... } C to Rust easy: #[no_mangle] extern "C" fn foo(...) { ... } Ruby, Python, etc to Rust see e.g. https://github.com/wycats/rust-bridge
  • 112. Pivot from C/C++ to Rust Maidsafe is one example of this
  • 113. Rust as enabler of individuals From "mere script programmer" to "lauded systems hacker"
  • 114. Or if you prefer: Enabling sharing systems hacking knowledge with everyone Programming in Rust has made me look at C++ code in a whole new light
  • 116. Watch the video with slide synchronization on InfoQ.com! https://www.infoq.com/presentations/rust