i believe in rust

20
I belive in Rust An intruduction to the Rust programming language 54°26'42" S 3°19'2" E 22. august 2012 1 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

Upload: reidar-sollid

Post on 20-Jun-2015

1.967 views

Category:

Documents


2 download

TRANSCRIPT

Page 1: I believe in rust

1 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

I belive in RustAn intruduction to the Rust programming language

54°26'42" S 3°19'2" E

22. august 2012

Page 2: I believe in rust

2 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

Disclaimer

22. august 2012

• I am an Rust newbie• Rust is in 0.31 and have probably

changed since I wrote these slides. Example code might not compile with the latest and greatest.

Page 3: I believe in rust

3 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

So what is Rust

22. august 2012

• A programming language from Mozilla labs

• Compiled un-managed language• Ahead of time compiler• Concurrent-oriented– Message passing– Default immutable variables (mutable keyword)

• Lambda expressions with a lot if easy to use code

• Classes and traits• No NPE crashes, libs use Option<T> or

Result<T,U>• Unsigned types (Singed byte is a bad

idea)

Page 4: I believe in rust

4 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

Preparing for hello world

22. august 2012

• Git clone and build from source– Dependencies

• G++ 4.4 or above or clang++3.x• Python 2.6 or later• Gnu make 3.8.1 or later• curl

• Download binaries• Emacs and Eclipse plugins• http://dl.rust-lang.org/doc/

tutorial.html

Page 5: I believe in rust

5 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E 22. august 2012

Simple hello world

22. august 20125 I belive in Rust JavaZone 2012

Page 6: I believe in rust

6 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

Tasks

22. august 2012

Page 7: I believe in rust

7 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

Task management

22. august 2012

• An Rust program consists of a tree of tasks, with their own stack and sole ownership of allocated heap data

• Communicate through ports and channels

• Propagates failures to its parent (the task spawned this one) unless unsupervise function is called.

• May be executed in parallel and are scheduled by the runtime

• Has its own GC

Page 8: I believe in rust

Proper hello world

22. august 20128 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

Page 9: I believe in rust

9 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

Rust vs Java

22. august 2012

• Java has global GC Rust has per-task GC

• Rust does not share memory but communicate through message passing

• Rust is compiled to native AOT compiler

• Rust is per default immutable– Use the keyword mut to create mutable

• Rust has unsigned types• No null pointer crashes• High order functions for iteration

Page 10: I believe in rust

10 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

High order functions

22. august 2012

Page 11: I believe in rust

11 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

Pattern matching

22. august 2012

Page 12: I believe in rust

12 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

Pattern matching example

22. august 2012

Page 13: I believe in rust

13 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

Ports and channels

22. august 2012

Page 14: I believe in rust

14 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

Ports and channels example

22. august 2012

Page 15: I believe in rust

15 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

Modules and crates

22. august 2012

Page 16: I believe in rust

16 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

Unit testing

22. august 2012

• Compiles with the --test flag and run

• Not external lib but part of the compiler

Page 17: I believe in rust

17 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

The Servo Parallel Browser Project

22. august 2012

• Servo is a web browser engine written in the Rust language. It is currently developed on OS X and Linux.

• https://github.com/mozilla/servo

Page 18: I believe in rust

18 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

Yegge’s laundry list

22. august 2012

• Dave Cheneys blog post on Go – “While languages like Julia or Rust

approach 100% coverage of Yegge’s laundry list, it is still to be seen if they will achieve mainstream adoption.”

Page 19: I believe in rust

19 I belive in Rust JavaZone 2012 | 54°26'42" S 3°19'2" E

The list for Go

22. august 2012

Page 20: I believe in rust