1. 54 26'42" S 3 19'2" E
I belive in Rust
An intruduction to the Rust programming language
1 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
2. Disclaimer
• 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.
2 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
3. So what is Rust
• 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)
3 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
4. Preparing for hello world
• 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
4 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
5. Simple hello world
5 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
6. Tasks
6 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
7. Task management
• 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
7 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
8. Proper hello world
8 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
9. Rust vs Java
• 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
9 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
10. High order functions
10 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
11. Pattern matching
11 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
13. Ports and channels
13 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
14. Ports and channels example
14 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
15. Modules and crates
15 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
16. Unit testing
• Compiles with the --test flag and run
• Not external lib but part of the compiler
16 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
17. The Servo Parallel Browser
Project
• 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
17 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
18. Yegge’s laundry list
• 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.”
18 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
19. The list for Go
19 22. august 2012 I belive in Rust JavaZone 2012 | 54 26'42" S 3 19'2" E
Hinweis der Redaktion
An executing Rust program consists of a tree of tasks, each with their own stack, and sole ownership of their allocated heap data. Tasks communicate with each other using ports and channels.When a task fails, that failure will propagate to its parent (the task that spawned it) and the parent will fail as well. The reverse is not true: when a parent task fails its children will continue executing. When the root (main) task fails, all tasks fail, and then so does the entire process.A task may remove itself from this failure propagation mechanism by calling the unsupervise function, after which failure will only result in the termination of that task.Tasks may execute in parallel and are scheduled automatically by the runtime.