Rust
- Created by Graydon Hoare
- Funded by Mozilla
- Primary goal: A safer systems language
- First version: 2010
- Current version 1.5
- Main project: Servo browser engine
• Provide the right abstractions
• Provide awesome tools
• Allow making mistakes
• Build a helpful community
Systems Programming
can be fun!
Slide 6
Slide 6 text
RUST: High level on bare metal
Slide 7
Slide 7 text
No content
Slide 8
Slide 8 text
Where Rust makes sense
• Operating Systems
• Encryption
• Databases
• Graphics programming
• …
(everywhere you need speed and safety)
Slide 9
Slide 9 text
Where Rust makes sense
glium
• High-level wrapper around OpenGL
• Avoids all OpenGL errors
diesel • A safe, extensible ORM and Query Builder
• Operating System written in pure Rust,
designed to be modular and secure
Redox
crossbeam • A collection of lock-less data structures
turbine
• A high-performance, non-locking, inter-task
communication library written in Rust.
• Go channels on steroids
Slide 10
Slide 10 text
What I like about…
• PHP: Package manager, Community
• Python: Syntax, Libraries
• Golang: Tooling, Documentation, Concurrency
• C: Speed, no overhead
Slide 11
Slide 11 text
What I like about…
• PHP: Package manager, Community
• Python: Syntax, Libraries
• Golang: Tooling, Documentation, Concurrency
• C: Speed, no overhead
RUST
Slide 12
Slide 12 text
What sucks about…
• PHP: Syntax (a bit), legacy functions
• Python: Package manager, 2 vs 3
• Golang: Error handling, package
manager, no generics, Syntax (a bit)
• C: Missing package manager, safety
Slide 13
Slide 13 text
Complexity vs Speed
• PHP
• Python
• Golang
• Rust
• C
Faster „Easier“
Slide 14
Slide 14 text
Popular systems
languages
Type safety
Type
expression
Type
checking
Garbage
Collector
C unsafe explicit static No
C++ unsafe explicit static No
Go safe implicit/explicit static Yes
Rust safe implicit/explicit static/dynamic optional
Slide 15
Slide 15 text
#include
#include
#include
int main() {
std::vector v;
v.push_back("foo");
auto const &x = v[0];
v.push_back("bar");
// Undefined behavior!
std::cout << x << '\n';
}
Slide 16
Slide 16 text
What went wrong?
Your vector is just an address in memory
Slide 17
Slide 17 text
When it grows, it might be moved!
What went wrong?
Slide 18
Slide 18 text
Your old pointer still exists.
What went wrong?
Slide 19
Slide 19 text
…but it points to „something“
What went wrong?
Slide 20
Slide 20 text
There’s multiple mutable references to the same data
Observation
Slide 21
Slide 21 text
There’s multiple mutable references to the same data
Ownership
Avoid
There should only be one owner at the same time
In Rust this is enforced by the compiler!
Slide 22
Slide 22 text
Is this really an issue?
Search results on StackOverflow.com:
segfault 10.899 results
segmentation fault 21.238 results
memory leak 55.064 results
Slide 23
Slide 23 text
Ownership
+ Borrowing
+ Lifetimes
= data safety
Three important concepts in Rust
Slide 24
Slide 24 text
Ownership in real life
Me You
Here’s a present!
Book owner
Slide 25
Slide 25 text
Ownership in real life
Me You
Thanks Dude!
Book owner
Slide 26
Slide 26 text
Ownership in real life
Me You
Book owner
Slide 27
Slide 27 text
Borrowing in real life
Me You
Nice book! Can I lend it?
Book owner
Slide 28
Slide 28 text
Borrowing in real life
Me You
Thanks Dude!
Sure!
Book owner
Slide 29
Slide 29 text
Borrowing in real life
Me You
Book owner
Slide 30
Slide 30 text
Borrowing in real life
Me You
Thanks for lending
Book owner
Slide 31
Slide 31 text
fn f(x: Type) {...} fn f(x: &Type) {...} fn f(x: &mut Type) {...}
Shared borrow Mutable borrow
Ownership
• one owner
• mutable
• readable
• Share as you like
• immutable
• readable
• one at a time
• mutable
• readable
Slide 32
Slide 32 text
Show us some code
already!
Slide 33
Slide 33 text
What sucks about
Rust
• Fighting with the Borrow checker
• Syntax (a bit)
• Missing packages (you can help!)
• probably more…
Slide 34
Slide 34 text
Tool list
Unit testing: builtin
Package manager
Syntax highlighting
Formatting
Code completion
Debugging
Code linter
Benchmarking
Profiling
Code coverage
Slide 35
Slide 35 text
https://doc.rust-lang.org/book/testing.html
Unit testing
Slide 36
Slide 36 text
Unit testing: builtin
Package manager: cargo
Syntax highlighting
Formatting
Code completion
Debugging
Code linter
Benchmarking
Profiling
Code coverage
Tool list
kcov …is a code coverage tester for
compiled programs, Python
scripts and shell scripts
language: rust
matrix:
fast_finish: true
include:
- rust: nightly
env: FEATURES="--features nightly"
sudo: false
- rust: nightly
env: FEATURES="--features nightly" BENCH=true
sudo: false
- rust: beta
sudo: true
after_success: |
sudo apt-get install libcurl4-openssl-dev libelf-dev libdw-dev &&
wget https://github.com/SimonKagstrom/kcov/archive/master.tar.gz &&
tar xzf master.tar.gz && mkdir kcov-master/build && cd kcov-master/build && cmake .. && make &&
sudo make install && cd ../.. &&
kcov --coveralls-id=$TRAVIS_JOB_ID --exclude-pattern=/.cargo target/kcov target/debug/hyper-*
Put this into your .travis.yml:
Slide 48
Slide 48 text
Summary
Lots of work to do
But impressive start
Slide 49
Slide 49 text
We need to focus on those…
Unit testing
Package manager
Syntax highlighting
Formatting
Code completion
Debugging
Code linter
Benchmarking
Profiling
Code coverage