Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Rust is the only thing left
Search
Florian Gilcher
November 18, 2014
Programming
1
76
Rust is the only thing left
My Talk at Strange Group Berlin about Rust.
Florian Gilcher
November 18, 2014
Tweet
Share
More Decks by Florian Gilcher
See All by Florian Gilcher
A new contract with users
skade
1
480
Using Rust to interface with my dive computer
skade
0
230
async/.await with async-std
skade
1
780
Training Rust
skade
1
98
Internet of Streams - IoT in Rust
skade
0
83
How DevRel is failing communities
skade
0
71
The power of the where clause
skade
0
620
Three Years of Rust
skade
1
170
Rust as a CLI language
skade
1
200
Other Decks in Programming
See All in Programming
データの民主化を支える、透明性のあるデータ利活用への挑戦 2025-06-25 Database Engineering Meetup#7
y_ken
0
300
WindowInsetsだってテストしたい
ryunen344
1
190
技術同人誌をMCP Serverにしてみた
74th
0
240
A comprehensive view of refactoring
marabesi
0
970
XP, Testing and ninja testing
m_seki
3
160
Julia という言語について (FP in Julia « SIDE: F ») for 関数型まつり2025
antimon2
3
970
AWS CDKの推しポイント 〜CloudFormationと比較してみた〜
akihisaikeda
3
300
アンドパッドの Go 勉強会「 gopher 会」とその内容の紹介
andpad
0
260
すべてのコンテキストを、 ユーザー価値に変える
applism118
2
550
型付きアクターモデルがもたらす分散シミュレーションの未来
piyo7
0
800
『自分のデータだけ見せたい!』を叶える──Laravel × Casbin で複雑権限をスッキリ解きほぐす 25 分
akitotsukahara
1
420
生成AIコーディングとの向き合い方、AIと共創するという考え方 / How to deal with generative AI coding and the concept of co-creating with AI
seike460
PRO
1
330
Featured
See All Featured
The Pragmatic Product Professional
lauravandoore
35
6.7k
Principles of Awesome APIs and How to Build Them.
keavy
126
17k
Practical Tips for Bootstrapping Information Extraction Pipelines
honnibal
PRO
20
1.3k
KATA
mclloyd
29
14k
The World Runs on Bad Software
bkeepers
PRO
69
11k
Stop Working from a Prison Cell
hatefulcrawdad
270
20k
Keith and Marios Guide to Fast Websites
keithpitt
411
22k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
228
22k
Build The Right Thing And Hit Your Dates
maggiecrowley
36
2.8k
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.8k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
670
Agile that works and the tools we love
rasmusluckow
329
21k
Transcript
None
$ cat .profile GIT_AUTHOR_NAME=Florian Gilcher
[email protected]
TM_COMPANY=Asquera GmbH TWITTER_HANDLE=argorak GITHUB_HANDLE=skade
• Backend developer • Focused on infrastructure and data- bases
• Elasticsearch Usergroup • mrgn.in meetup • Rust Usergroup (co-org)
• organizer alumni eurucamp • organizer alumni JRubyConf.EU • Ruby Berlin board member
I generally have a nose for new things: • learned
Ruby before Rails was a thing • Elasticsearch early adopter • Now into Rust
Rust is the Only Thing That's Left
Not necessarily new, but definitely emerging
Three goals • Safe • Concurrent • (Predictably) Fast
Safe • static type system with local type inference •
null-pointer free (except...) • unique pointers all the way
Concurrent • Mutability as a first-class concept • No shared
mutable state • Important base types built in
(Predictably) fast • No hidden allocations • Predictable deallocations •
Abstractions must be zero-cost or cheap (computation-wise) • (except...) optional unsafe sublan- guage
We're aiming at C here • Controllable memory-layout • Can
generate C-ABI binaries • No runtime • Close to the machine
What does it look like?
fn main() { println!("Hello strange-group!"); }
Braces, like Richie indented
pub type Id = u64; pub enum KeyType { Queue,
Chunk } pub struct Key { id: Id, keytype: KeyType, }
#[repr(u64)] pub enum KeyType { Queue, Chunk }
#[repr(u64)] #[deriving(Show, PartialEq, Eq, PartialOrd, Ord, Clone)] pub enum KeyType
{ Queue, Chunk }
Generics enum Result<T, E> { Ok(T), Err(E) } enum Option<T>
{ Some(T), None }
Traits
impl Key { pub fn default() -> Key { Key
{ keytype: Queue, id: 0 } } pub fn new(keytype: KeyType, id: Id) -> Key { Key { keytype: keytype, id: id } } pub fn compare(&self, other: &Key) -> Ordering { //... } }
pub trait Comparable { fn compare(&self, other: &Key) -> Ordering;
} impl Comparable for Key { fn compare(&self, other: &Key) -> Ordering { //... } }
(almost) everything is an expression fn main() { let foo
= if key.keytype == Queue { "this is a queue key" } else { "this is a chunk key" } println!(foo); }
fn main() { let key = Key { keytype: Queue,
id: 1 }; let foo = match key.keytype { Queue => "queue key", Chunk => "chunk key" }; println!("{}", foo); }
Semantic semicolons fn main() -> () { "Hello!" } //
error: mismatched types: expected `()`, found `&’static str` (expected (), found &-ptr) fn main() -> () { "Hello!"; }
Mutability fn main() { let x = 5i; x =
4i; } //error: re-assignment of immutable variable `x` //x = 4i; //...
fn main() { let mut x = 5i; x =
4i; }
References fn add_one(x: &int) -> int { *x + 1
} fn main() { assert_eq!(6, add_one(&5)); }
fn main() { let x = 5i; let y =
&mut x; } //error: cannot borrow immutable local variable `x` as mutable fn main() { let mut x = 5i; let y = &mut x; }
trait Access for Database { fn get(&self, key: &[u8]) {
//... } fn put(&mut self, key: &[u8], value: &[u8]) { //... } }
Mutability runs deep
Ownership, borrowing
• Every resource in Rust has a single owner •
controls when the resource is deal- located.
• may lend that resource, immutably, as much as wanted
• may lend that resource, mutably, to a single borrower. • borrows cannot outlive the owner
Refcounting for people that can only count to one.
Ownership can move, but never be copied.
Values can be copied, cloned, etc. and will then be
owned by someone else.
Decidable at compile time.
Predictible, safe memory management without garbage collection.
fn main() { let tempdir = try!( TempDir::new("strange-group") ); let
mut tempfile = try!(File::create( &tempdir.path().join("tmp") )); // look, no close necessary! }
Deallocation and destructors run when leaving the scope.
fn main() { let tempdir = try!( TempDir::new("strange-group") ); let
mut tempfile = try!(File::create( &tempdir.path().join("tmp") )); drop(tempfile); }
#[inline] #[stable] pub fn drop<T>(_x: T) { } // takes
ownership, does nothing
Mutability tracking, a set of carefully chosen base traits and
borrow rules form the basis of making Rust a safe language for concurrent use.
No mutable borrows over boundaries, special traits for things that
can be sent between tasks.
FFI #[repr(c)] struct MyStruct { one: int, two: int }
// free movement between C-Space and Rust-Space
#[link(name = "tsm")] extern { pub fn tsm_vte_new( out: *mut
*mut tsm_vte, con: *mut tsm_screen, write_cb: tsm_write_cb, data: *mut c_void, log: Option<tsm_log_t>, log_data: *mut c_void) -> c_int; } extern "C" fn write_cb(_: *const tsm_vte, _: *const u8, _: size_t, _: c_void) {}
unsafe impl Key { pub fn from_u8(key: &[u8]) -> &Key
{ use std::mem::transmute; assert!(key.len() == 16) unsafe { transmute(key.as_ptr()) } } }
A sublanguage for pointer fiddling, unsafe memory operations for speed,
interfacing with C, etc.
None
Aggressive bias towards using the language to gain insight
Rust wants you to declare a lot.
Rust has a complainer.
The amount of lints built into the compiler is mindboggling,
strict and very useful.
use std::io::TempDir; fn main() { TempDir::new("strange-group"); } // warning: unused
result which must be used, #[warn(unused_must_use)] on by default
use std::io::TempDir; #[deny(unused_must_use)] fn main() { TempDir::new("strange-group"); } // error:
unused result which must be used
Results are everywhere.
#![deny(missing_docs)] #![deny(warnings)] // Karma boost!
This is a first-class language feature, not a compiler feature!
• Unused documentation • Type casing • Unused code •
Unused struct fields • private struct leaks
Good doc tools • rustdoc allows testing of embedded code
• most example code in the rust world is runnable for that reason • play.rust-lang.org allows playing with it
Dependency management tools • Cargo, like Bundler for Rust •
The third try • Sane default code layout rules • Provides test harness
Bias towards good documentation • Guide currently written by a
paid author (Steve Klabnik) • Good documentation of the stable stdlib • Stability-markers throughout
Production use: • Used to build a browser engine passing
ACID 2 (Servo) • Used at skylight.io • A couple of small tooling tasks
Extreme focus on community • Community code of conduct... •
... that has seen necessity and use • IRC and /r/rust are very well mod- erated • Awesome community code reviews
• A community CI server that trigger travis builds nightly
• Weekly newsletters about changes • open core meetings • meetup groups around the world
Emerging
Release of 1.0 will be in January or early 2015.
backwards-compatible releases afterwards, every 6 weeks
beta and nightly channels
Stability Rust has no runtime. Bugs with failing compilations are
possible (albeit rare), but the resulting binaries are of good quality.
Usage Rust is a good language to bind to C
libraries and provides tools to easily abstract over C.
It is also a good language to replace C libraries.
Rust aims to fulfill all your needs when generating native
binaries, down to specifics of microprocessors.
Game development takes huge interest.
Outstanding issues Lack of important libraries, most notably: • HTTP
• Fast serialization/deserialization (being reworked) • DB drivers, interfaces, etc.
Can I use it now? Yes.
Up until 1.0, use nightly builds.
It has been used for serious software for a while
now.
Type system Rust uses a linar (affine, to be exact)
type system without ever mentioning it or having you bother with it. Also, no higher-kinded types for 1.0, because there needs to be a 1.0.
A bit of history
Rust, 3 years ago
fn draw_a_square_and_a_circle(gfx: graphics_context) { let s = @square(...); let c
= @circle(...); let objs = [s as draw, c as draw]; draw_all(gfx, objs); } fn draw_many<D:draw>(gfx: graphics_context, drawables: [D]) { for drawables.each {|drawable| drawable.draw(gfx) } }
• Classes, Interfaces • Optional Garbage collection • Task-Runtime using
libuv under the hood (later: multiple) • Star Wars, redefined: &, *, ~, @ as pointer sigils • A lot more special cases (e.g. owned pointers vs. gc-ed pointers)
If there are two ways, let's do them both
Rust, today
• Traits, Structs and Enums only • No garbage collection
• All traces of runtimes removed • Star Wars, old-school: &, * are the only sigils left • a rather lean language
There are multiple ways, let’s provide the building blocks.
Multiple rewrites of important parts of the stdlib.
Trimming and throwing away is a strong part of the
culture until release.
Clear focus and target.
Rust is the only thing that’s left after that.
Thank you! I’ll post references to the meetup group later.
Coda
Rust has also been used for silly software for a
while now.
There’s an issue I’d like to speak about.
SL(1) ==== ________ _____ _D _| |_______/ \\__I_I_____===__|____ |(_)— |
H\\________/ | | =|___ __ / | | H | | | | ||_| | | | | H |__——————–| [___] | | ________|___H__/__|_____/[][]~\\______| |/ | |———–I_____I [][] [] D |=======|__ __/ =| o |=-~~\\ /~~\\ /~~\\ /~~\\ ____Y_____ |/-=|___|= || || || |_____/~\\_ \\_/ \\O=====O=====O=====O_/ \\_
• sl(1) is in danger • appreciation is sinking •
distributions ship it with options allowing to stop the train (debian) • in outdated versions (debian)
I’m pretty sure someone is rebuilding it as a systemd
module.
Rebuild your own sl(1), as close to the original as
possible, in your favourite language, system, whatever.
https://github.com/mtoyoda/sl
Tweet to: @argorak