Why Rust?
- Düsseldorf, Germany
- Backend Engineer at trivago
- Website performance team
- Worked a lot with Python and PHP
- Likes hot chocolate
@matthiasendler
Matthias Endler
mre
C
me
C++
System Programming
Memory management
Error handling
Static Typing
Compiling
…
Rust
- Created by Graydon Hoare
- Funded by Mozilla
- First version: 2010
- Current stable version 1.8
A safe systems language
System Programming
is challenging!
• Provide the right abstractions
• Provide awesome tools
• Allow making mistakes
• Build a helpful community
System Programming
can be fun!
Complexity vs Speed
• PHP
• Python
• Golang
• Rust
• C
Faster „Easier“
RUST: High level on bare metal
Where Rust shines
Everywhere you want speed and safety
• Operating Systems
• Compilers
• Emulators

Encryption
• Databases

Numerics
• Graphics Programming
• Data Pipelines

Finance
• …
struct Person {
first_name: String,
last_name: String,
age: i32
}
impl Person {
pub fn new(first_name: String, last_name: String, age: i32) -> Person {
Person {
first_name: first_name,
last_name: last_name,
age: age
}
}
}
fn main() {
let mut vec = Vec::new();
vec.push(Person::new(String::from("Austin"), String::from("Powers"), 13));
vec.push(Person::new(String::from("Dr."), String::from("Evil"), 30));
for person in &vec {
let result = match person.age {
0...18 => "Teenager",
18 => "Old enough to go to war",
_ => "Too Old"
};
}
}
RUST
What I like about…
• PHP: Package manager, Community
• Python: Syntax, Libraries
• Golang:Tooling, Documentation, Concurrency
• C: Speed, no overhead
What I like about…
• PHP: Package manager, Community
• Python: Syntax, Libraries
• Golang:Tooling, Documentation, Concurrency
• C: Speed, no overhead
RUST
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
What sucks about
Rust
• Syntax (a bit)
• „Fighting with the Borrow checker“
• Missing packages (you can help!)
• probably more…
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
#include <iostream>
#include <vector>
#include <string>
int main() {
std::vector<std::string> v;
v.push_back("foo");
auto const &x = v[0];
v.push_back("bar");
// Undefined behavior!
std::cout << x;
}
C++
There’s multiple mutable references to the same data
auto const &x = v[0] v was copied to new location
fn main() {
let mut v = Vec::new();
v.push("foo");
let mut x = &mut v[0];
v.push("bar");
println!("{}", x)
}
RUST
Rust
- No data races
- No segfaults
- No null pointers
- No race conditions
John Carmack, Creator of Doom and Quake
fn f(x: Type) {...}
fn f(x: &Type) {...}
fn f(x: &mut Type) {...}
Mutable borrow
Ownership
• Share as you like
• read-only
• one at a time
• read/write
Immutable borrow
• Total control
• read-write
IDEs?
Visual Studio
Visual Studio Code using Rusty Code plugin
Atom with language-rust plugin
Some common cargo commands are:
build Compile the current project
doc Build this project's and its dependencies' documentation
new Create a new cargo project
run Build and execute src/main.rs
test Run the tests
bench Run the benchmarks
update Update dependencies listed in Cargo.lock
search Search registry for crates
publish Package and upload this project to the registry
install Install a Rust binary
Cargo
the Rust package manager
Updating registry `https://github.com/rust-lang/crates.io-index`
simple_parallel (0.3.0) Straight-forward functions and types for basic data
parallel operations, including parallel maps, for loops and thread pools.
forkjoin (2.3.0) A work stealing fork-join parallelism library for Rust
arrayfire (3.2.0) ArrayFire is a high performance software library for
parallel computing with an easy-to-use API. Its array based function set m…
parry (0.1.0) Parallel array processing: deflect performance
problems.
mpi (0.2.0) Message Passing Interface bindings for Rust
specs (0.6.1) Parallel Entity-Component System. Specs is a parallel
ECS in Rust. It combines the performance of the beast with the flexibili…
collenchyma (0.0.8) high-performance computation on any hardware
substudy (0.4.0) Language-learning tools for working with parallel,
bilingual subtitles and media files.
crossbeam (0.2.9) Support for lock-free data structures, synchronizers,
and parallel programming
abc (0.2.3) An implementation of Karaboga's Artificial Bee Colony
algorithm.
... and 27 crates more (use --limit N to see more)
››› cargo search parallel
My tool wishlist
Unit testing: cargo test
Package manager
Syntax highlighting
Formatting
Code completion
Debugging
Code linter
Benchmarking
Profiling
Code coverage
https://doc.rust-lang.org/book/testing.html
Unit testing
My tool wishlist
Unit testing: cargo test
Package manager: cargo build/run/install
Syntax highlighting
Formatting
Code completion
Debugging
Code linter
Benchmarking
Profiling
Code coverage
My tool wishlist
Unit testing: cargo test
Package manager: cargo build/run/install
Syntax highlighting: many plugins
Formatting
Code completion
Debugging
Code linter
Benchmarking
Profiling
Code coverage
My tool wishlist
Unit testing: cargo test
Package manager: cargo build/run/install
Syntax highlighting: many plugins
Formatting: rustfmt
Code completion
Debugging
Code linter
Benchmarking
Profiling
Code coverage
My tool wishlist
Unit testing: cargo test
Package manager: cargo build/run/install
Syntax highlighting: many plugins
Formatting: rustfmt
Code completion: racer
Debugging
Code linter
Benchmarking
Profiling
Code coverage
My tool wishlist
Unit testing: cargo test
Package manager: cargo build/run/install
Syntax highlighting: many plugins
Formatting: rustfmt
Code completion: racer
Debugging: rust gdb?
Code linter
Benchmarking
Profiling
Code coverage
My tool wishlist
Unit testing: cargo test
Package manager: cargo build/run/install
Syntax highlighting: many plugins
Formatting: rustfmt
Code completion: racer
Debugging: rust gdb?
Code linter: clippy
Benchmarking
Profiling
Code coverage
My tool wishlist
Unit testing: cargo test
Package manager: cargo build/run/install
Syntax highlighting: many plugins
Formatting: rustfmt
Code completion: racer
Debugging: rust gdb?
Code linter: clippy
Benchmarking: cargo bench
Profiling
Code coverage
My tool wishlist
Unit testing: cargo test
Package manager: cargo build/run/install
Syntax highlighting: many plugins
Formatting: rustfmt
Code completion: racer
Debugging: rust gdb?
Code linter: clippy
Benchmarking: cargo bench
Profiling: meh…
Code coverage
My tool wishlist
Unit testing: cargo test
Package manager: cargo build/run/install
Syntax highlighting: many plugins
Formatting: rustfmt
Code completion: racer
Debugging: rust gdb?
Code linter: clippy
Benchmarking: cargo bench
Profiling: meh… torch?
Code coverage
https://llogiq.github.io/2015/07/15/profiling.html
Calls
Time
My tool wishlist
Unit testing: cargo test
Package manager: cargo build/run/install
Syntax highlighting: many plugins
Formatting: rustfmt
Code completion: racer
Debugging: rust gdb?
Code linter: clippy
Benchmarking: cargo bench
Profiling: meh… torch?
Code coverage: kcov?
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:
Summary
Lots of work to do
But impressive start
We need to focus on those…
• Debugging
• Profiling
• Code Coverage
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
Bonus
rr - a reverse debugger

(http://rr-project.org/)
Dash - Offline API Documentation browser for Mac
(https://kapeli.com/dash)
Crates.io reverse package lookup

(https://crates.io/crates/serde/reverse_dependencies)
www.meetup.com/Rust-Amsterdam
https://users.rust-lang.org/
Even more at
https://gist.github.com/nrc/a3bbf6dd1b14ce57f18c
http://kukuruku.co/hub/rust/comparing-rust-and-cpp
Why Rust? - Matthias Endler - Codemotion Amsterdam 2016

Why Rust? - Matthias Endler - Codemotion Amsterdam 2016

  • 1.
  • 2.
    - Düsseldorf, Germany -Backend Engineer at trivago - Website performance team - Worked a lot with Python and PHP - Likes hot chocolate @matthiasendler Matthias Endler mre
  • 3.
  • 5.
    System Programming Memory management Errorhandling Static Typing Compiling …
  • 6.
    Rust - Created byGraydon Hoare - Funded by Mozilla - First version: 2010 - Current stable version 1.8 A safe systems language
  • 7.
  • 8.
    • Provide theright abstractions • Provide awesome tools • Allow making mistakes • Build a helpful community System Programming can be fun!
  • 9.
    Complexity vs Speed •PHP • Python • Golang • Rust • C Faster „Easier“
  • 10.
    RUST: High levelon bare metal
  • 11.
    Where Rust shines Everywhereyou want speed and safety • Operating Systems • Compilers • Emulators
 Encryption • Databases
 Numerics • Graphics Programming • Data Pipelines
 Finance • …
  • 12.
    struct Person { first_name:String, last_name: String, age: i32 } impl Person { pub fn new(first_name: String, last_name: String, age: i32) -> Person { Person { first_name: first_name, last_name: last_name, age: age } } } fn main() { let mut vec = Vec::new(); vec.push(Person::new(String::from("Austin"), String::from("Powers"), 13)); vec.push(Person::new(String::from("Dr."), String::from("Evil"), 30)); for person in &vec { let result = match person.age { 0...18 => "Teenager", 18 => "Old enough to go to war", _ => "Too Old" }; } } RUST
  • 13.
    What I likeabout… • PHP: Package manager, Community • Python: Syntax, Libraries • Golang:Tooling, Documentation, Concurrency • C: Speed, no overhead
  • 14.
    What I likeabout… • PHP: Package manager, Community • Python: Syntax, Libraries • Golang:Tooling, Documentation, Concurrency • C: Speed, no overhead RUST
  • 15.
    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
  • 16.
    What sucks about Rust •Syntax (a bit) • „Fighting with the Borrow checker“ • Missing packages (you can help!) • probably more…
  • 17.
    Type safety Type expression Type checking Garbage Collector C unsafeexplicit static No C++ unsafe explicit static No Go safe implicit/explicit static Yes Rust safe implicit/explicit static/dynamic optional
  • 18.
    #include <iostream> #include <vector> #include<string> int main() { std::vector<std::string> v; v.push_back("foo"); auto const &x = v[0]; v.push_back("bar"); // Undefined behavior! std::cout << x; } C++
  • 19.
    There’s multiple mutablereferences to the same data auto const &x = v[0] v was copied to new location
  • 20.
    fn main() { letmut v = Vec::new(); v.push("foo"); let mut x = &mut v[0]; v.push("bar"); println!("{}", x) } RUST
  • 21.
    Rust - No dataraces - No segfaults - No null pointers - No race conditions
  • 22.
    John Carmack, Creatorof Doom and Quake
  • 23.
    fn f(x: Type){...} fn f(x: &Type) {...} fn f(x: &mut Type) {...} Mutable borrow Ownership • Share as you like • read-only • one at a time • read/write Immutable borrow • Total control • read-write
  • 24.
  • 25.
  • 26.
    Visual Studio Codeusing Rusty Code plugin
  • 27.
  • 28.
    Some common cargocommands are: build Compile the current project doc Build this project's and its dependencies' documentation new Create a new cargo project run Build and execute src/main.rs test Run the tests bench Run the benchmarks update Update dependencies listed in Cargo.lock search Search registry for crates publish Package and upload this project to the registry install Install a Rust binary Cargo the Rust package manager
  • 29.
    Updating registry `https://github.com/rust-lang/crates.io-index` simple_parallel(0.3.0) Straight-forward functions and types for basic data parallel operations, including parallel maps, for loops and thread pools. forkjoin (2.3.0) A work stealing fork-join parallelism library for Rust arrayfire (3.2.0) ArrayFire is a high performance software library for parallel computing with an easy-to-use API. Its array based function set m… parry (0.1.0) Parallel array processing: deflect performance problems. mpi (0.2.0) Message Passing Interface bindings for Rust specs (0.6.1) Parallel Entity-Component System. Specs is a parallel ECS in Rust. It combines the performance of the beast with the flexibili… collenchyma (0.0.8) high-performance computation on any hardware substudy (0.4.0) Language-learning tools for working with parallel, bilingual subtitles and media files. crossbeam (0.2.9) Support for lock-free data structures, synchronizers, and parallel programming abc (0.2.3) An implementation of Karaboga's Artificial Bee Colony algorithm. ... and 27 crates more (use --limit N to see more) ››› cargo search parallel
  • 30.
    My tool wishlist Unittesting: cargo test Package manager Syntax highlighting Formatting Code completion Debugging Code linter Benchmarking Profiling Code coverage
  • 31.
  • 32.
    My tool wishlist Unittesting: cargo test Package manager: cargo build/run/install Syntax highlighting Formatting Code completion Debugging Code linter Benchmarking Profiling Code coverage
  • 33.
    My tool wishlist Unittesting: cargo test Package manager: cargo build/run/install Syntax highlighting: many plugins Formatting Code completion Debugging Code linter Benchmarking Profiling Code coverage
  • 34.
    My tool wishlist Unittesting: cargo test Package manager: cargo build/run/install Syntax highlighting: many plugins Formatting: rustfmt Code completion Debugging Code linter Benchmarking Profiling Code coverage
  • 35.
    My tool wishlist Unittesting: cargo test Package manager: cargo build/run/install Syntax highlighting: many plugins Formatting: rustfmt Code completion: racer Debugging Code linter Benchmarking Profiling Code coverage
  • 36.
    My tool wishlist Unittesting: cargo test Package manager: cargo build/run/install Syntax highlighting: many plugins Formatting: rustfmt Code completion: racer Debugging: rust gdb? Code linter Benchmarking Profiling Code coverage
  • 37.
    My tool wishlist Unittesting: cargo test Package manager: cargo build/run/install Syntax highlighting: many plugins Formatting: rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking Profiling Code coverage
  • 38.
    My tool wishlist Unittesting: cargo test Package manager: cargo build/run/install Syntax highlighting: many plugins Formatting: rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking: cargo bench Profiling Code coverage
  • 39.
    My tool wishlist Unittesting: cargo test Package manager: cargo build/run/install Syntax highlighting: many plugins Formatting: rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking: cargo bench Profiling: meh… Code coverage
  • 40.
    My tool wishlist Unittesting: cargo test Package manager: cargo build/run/install Syntax highlighting: many plugins Formatting: rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking: cargo bench Profiling: meh… torch? Code coverage
  • 41.
  • 42.
    My tool wishlist Unittesting: cargo test Package manager: cargo build/run/install Syntax highlighting: many plugins Formatting: rustfmt Code completion: racer Debugging: rust gdb? Code linter: clippy Benchmarking: cargo bench Profiling: meh… torch? Code coverage: kcov?
  • 43.
    kcov …is acode 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:
  • 44.
    Summary Lots of workto do But impressive start
  • 45.
    We need tofocus on those… • Debugging • Profiling • Code Coverage
  • 46.
    glium • High-level wrapperaround 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
  • 47.
    Bonus rr - areverse debugger
 (http://rr-project.org/) Dash - Offline API Documentation browser for Mac (https://kapeli.com/dash) Crates.io reverse package lookup
 (https://crates.io/crates/serde/reverse_dependencies)
  • 48.
  • 49.
  • 50.