Slide 1

Slide 1 text

$ cat ~/.profile GIT_AUTHOR_NAME=Florian Gilcher GIT_AUTHOR_EMAIL=florian@asquera.de TWITTER_HANDLE=argorak GITHUB_HANDLE=skade BLOG=skade.me YAKS=yakshav.es

Slide 2

Slide 2 text

r Backend Developer r Rust Trainer r Ruby Programmer since 2003 r Rust Programmer since 2013 r CEO asquera GmbH

Slide 3

Slide 3 text

r Community person r Rust UG Berlin/Karlsruhe r Search UG Berlin r Ex-chair of Ruby Berlin e.V.

Slide 4

Slide 4 text

r Organiser eurucamp/jrubyconf.eu r Organiser RustFest r Part of the global Rust community team

Slide 5

Slide 5 text

r As a hobby, I shoot arrows at stuff

Slide 6

Slide 6 text

No content

Slide 7

Slide 7 text

Rust

Slide 8

Slide 8 text

r new systems programming language r powers and was developed in along with Servo, a new browser engine r by Mozilla

Slide 9

Slide 9 text

Providing an alternative to C/C++, but also higher-level languages.

Slide 10

Slide 10 text

r Safe r Concurrent r Fast

Slide 11

Slide 11 text

Pick Three

Slide 12

Slide 12 text

We’ve seen all those promises before, but how does Rust differ?

Slide 13

Slide 13 text

Core features

Slide 14

Slide 14 text

r Static type system with local type inference r Explicit mutability r Zero-cost abstractions r Runtime-independent concurrency primitives

Slide 15

Slide 15 text

r Explicit error control flow r No null r Static automatic memory manage- ment r No garbage collection

Slide 16

Slide 16 text

r Built with practical use in mind from the beginning r Features are there for the long run r Still with an eye on ergonomics r Great tooling and docs

Slide 17

Slide 17 text

extern crate tempdir; use tempdir::*; use std::fs::File; fn main() { let tempdir = TempDir::new("mozilla-roadshow"); let mut tempfile = match tempdir { Ok(dir) => { File::create( &dir.path().join("tmp") ) } Err(_) => { panic!("Couldn’t open tempdir") } } // look, no close necessary! }

Slide 18

Slide 18 text

Zero-cost Abstractions

Slide 19

Slide 19 text

extern crate tempdir; use tempdir::*; use std::fs::File; fn main() { let mut tempfile = TempDir::new("mozilla-roadshow") .and_then( |tempdir| { File::create( &tempdir.path().join("tmpfile") ) }) ); //... }

Slide 20

Slide 20 text

Despite using a closure, both ways of writing are basically equivalent.

Slide 21

Slide 21 text

Base concept: Mutability struct InnerData { val: i32 } struct Data { inner: InnerData } fn main() { let d = Data { inner: InnerData { val: 41 }}; d.inner.val = 42; // error: cannot assign to immutable field `d.inner.val` }

Slide 22

Slide 22 text

struct InnerData { val: i32 } struct Data { inner: InnerData } fn main() { let mut d = Data { inner: InnerData { val: 41 }}; d.inner.val = 42; }

Slide 23

Slide 23 text

Base concept: Ownership & Borrowing

Slide 24

Slide 24 text

r Every piece of data is uniquely owned r Ownership can be passed r Or access can be borrowed (muta- ble and immutable)

Slide 25

Slide 25 text

struct Data { value: String } fn main() { let data = Data { value: String::from("Hello Berlin!") }; taking_ownership(data); // data cannot be used here } fn taking_ownership(mut data: Data) { share_immutably(&data); share_mutably(&mut data); }

Slide 26

Slide 26 text

r You can borrow mutably once r Or multiple times immutably r Exclusive: mutable or immutable, never both

Slide 27

Slide 27 text

Mutability runs deep 100, 1000, 10.000 lines of called code, Rust keeps your mutability properties!

Slide 28

Slide 28 text

It is part of all signatures!

Slide 29

Slide 29 text

Rust makes reasoning about large systems more localised by reducing "action at distance".

Slide 30

Slide 30 text

Advanced concurrency checking

Slide 31

Slide 31 text

use std::rc::Rc; fn increment(m: &mut i32) { *m += 1 } fn main() { let ref_counted_integer = Rc::new(43); for i in 1..3 { let mut handle = ref_counted_integer.clone(); std::thread::spawn(move || { increment(&mut handle); // the trait `std::marker::Send` is not implemented for `std::rc::Rc` }); } }

Slide 32

Slide 32 text

This example could be a concurrency bug in many languages, or even a double-free!

Slide 33

Slide 33 text

Send & Sync

Slide 34

Slide 34 text

Rust has the concept of "sendable" and "syncable" values. The first can cross concurrency boundaries by being moved to the other side, the second allows sharing between.

Slide 35

Slide 35 text

This idea is independent of the used concurrency concept (evented, threading), etc.

Slide 36

Slide 36 text

It also doesn’t impose an approach! Shared-nothing as well as sharing synced values can be expressed!

Slide 37

Slide 37 text

Rust has libraries on top of that, providing threading, channels, and event-based concurrency.

Slide 38

Slide 38 text

r Tokio (https://tokio.rs/) r Rayon (https://crates.io/crates/rayon)

Slide 39

Slide 39 text

Low-level control & safety!

Slide 40

Slide 40 text

r Borrows are just pointers r Values are plain values just like in e.g. C

Slide 41

Slide 41 text

Rust gives you the possibility to opt out of safety, if absolutely necessary!

Slide 42

Slide 42 text

“ Safe code means you can take better risks.” – @QEDunham

Slide 43

Slide 43 text

Abstractions Rust provides higher-level abstractions through Generics and Traits, similar to C++ Templates or Java Generics.

Slide 44

Slide 44 text

The Road to Rust

Slide 45

Slide 45 text

Should you use Rust?

Slide 46

Slide 46 text

Yes!

Slide 47

Slide 47 text

Rust is not a simple language and many of its features are built for the long run. It takes a bit to click.

Slide 48

Slide 48 text

Take your time! The new things are worth it.

Slide 49

Slide 49 text

Rust is approachable r Easy to get an environment setup r Great docs through the book and a (almost) fully documented standard API r Build and depencency management baked in

Slide 50

Slide 50 text

Rust plays well with others r Rust interfaces with C or a C-FFI at almost no or zero cost r Binding generators C and C++ r High-level bindings for some lan- guages (Ruby, JavaScript)

Slide 51

Slide 51 text

Rust is a great partner Rust preserves the conveniences of high-level languages in low-level land

Slide 52

Slide 52 text

We don’t want to be your primary language at all cost, but be the best secondary one.

Slide 53

Slide 53 text

Rust is also built for gradual adoption.

Slide 54

Slide 54 text

Projects using Rust r GStreamer r Servo/Firefox r mononoke mercurial server r Redox OS r RTFM (Real Time For the Masses)

Slide 55

Slide 55 text

GStreamer GStreamer is introducing Rust, currently for plugins.

Slide 56

Slide 56 text

r Rust has better ergonomics at same speed r The 20 last security issues were memory bugs r Multithreading without support is a huge source of bugs

Slide 57

Slide 57 text

r Rust gives latency guarantees GC’ed languages cannot give r Runs well on memory-constrained environments

Slide 58

Slide 58 text

Beyond plain code

Slide 59

Slide 59 text

Commitment to stability r Rust is released every 6 weeks r Rust is backwards-compatible, with huge machinery to encure that r Currently at version 1.19.0

Slide 60

Slide 60 text

Commitment to stability r Rust stable allows no use of unsta- ble features r These are only available in nightly builds

Slide 61

Slide 61 text

Maturity r Code generation is provided through LLVM r No runtime: no bugs in the runtime r Very conservative approach to stdlib adoption

Slide 62

Slide 62 text

Cross-capabilities r rustc is a cross-compiler by default and the whole toolchain is aware r Almost-no-setup cross compilation! (getting better) r Rust supports embedded usecases

Slide 63

Slide 63 text

Great compiler support r rustc provides useful errors and warnings, including hints r currently in-development language server for supporting IDEs

Slide 64

Slide 64 text

Young language Rust is a relatively young language. That means the library ecosystem is in flux.

Slide 65

Slide 65 text

Many important libraries available: r Many protocols (HTTP, etc) r Parsers r Concurrency abstraction libraries

Slide 66

Slide 66 text

We have a huge ongoing effort to bring libraries close to 1.0 to 1.0.

Slide 67

Slide 67 text

Already there: r pre-built binary libs for 48 targets, ready to download r Full and advanced build tooling through cargo r webasm support (unstable)

Slide 68

Slide 68 text

A+ product

Slide 69

Slide 69 text

Lots and lots of infrastructure for CI, quality control and development.

Slide 70

Slide 70 text

Rust nightly usually builds since version 0.4.0.

Slide 71

Slide 71 text

Mozillas support helps there, tremendously!

Slide 72

Slide 72 text

Governance & Community Rust is developed by an in-house team at Mozilla. That does not mean in is dependent on it.

Slide 73

Slide 73 text

Most code changes come from external contributors!

Slide 74

Slide 74 text

All changes go through an open RFC process!

Slide 75

Slide 75 text

Mozilla has great experience with open discussion and processes and it shows!

Slide 76

Slide 76 text

Medium time to merged PR for changes: 6 days!

Slide 77

Slide 77 text

Friendly and active community!

Slide 78

Slide 78 text

Supporting commercial users r regular interviews with prod users, to hear about their issues r the core team can always be spoken to r consulting, development and train- ing available, through integer32 and asquera.

Slide 79

Slide 79 text

Commercial users r Mozilla r Dropbox r Facebook r Chef/Habitat r Theater Dortmund

Slide 80

Slide 80 text

r and 86 others. https://www.rust-lang.org/friends.html

Slide 81

Slide 81 text

Rust is not a hype

Slide 82

Slide 82 text

Rust is bringing safe programming to targets where it was unfeasible before while also bringing new things to the table to compete with other safe languages.

Slide 83

Slide 83 text

We do yearly surveys showing constant growth and improvements.

Slide 84

Slide 84 text

The strongest sub-community is...

Slide 85

Slide 85 text

Europe

Slide 86

Slide 86 text

r Rust Hack & Learn Berlin r 89 Meetups around the world r https://zurich.rustfest.eu

Slide 87

Slide 87 text

https://www.rust-lang.org https://community.rs https://twitter.com/rustvideos http://www.linuxhotel.de/kurs/rust/ http://asquera.de community-team@rust-lang.org