Hey, there's a local Rust meetup
in the Triangle area!
Check them out!
meetup.com/triangle-rustaceans/
circa 2006: Rough inception
2009: Tentative Mozilla involvement
2010: Public Mozilla commitment
2011: Compiler self-hosts, Servo begins
2012: First public release
2014: First beta release
2015: First stable release
~foo(lit,er,als) {
... a-random-string ...
}
User-defined literals
try {
...
} trap foo(x) {
fix x + 10;
} trap bar(y) {
log "got a bar";
fail;
}
Exceptions
if (... ) {
x = foo();
} else {
// "uh oh"
x = raise foo(gurgle);
}
Exceptions
fn f(int x, int y) -> () { ... }
type thunk1 = fn f(int x) -> ();
type thunk0 = fn f() -> ();
let thunk1 t1 = bind f(10,_);
let thunk1 t2 = bind f(_,10);
let thunk0 t0 = bind f(10,12);
No closures, only currying
// what
for (~auto e = v.(,)) {
out <| e <| endl;
}
Iterators and printing
Language runtime
Tuples
References
type mt = mod {
type e;
fn mk()->e;
fn eat(e)->nil;
}
let mt mv = mod {
type e = int;
fn mk()->e { ret 1; }
fn eat(int i) { }
}
use mt mm = mv;
let mm.e me = mm.mk();
mm.eat(me);
First-class modules
let set[int] s1 = listSet[int];
let set[int] s2 = treeSet[int];
let set[int] s3 = mod set[int] {
type t = []; ...
}
Square brackets
Typestate
category name(T) {
fn foo(params) -> ret {
/* self has type &T */
}
priv fn bar(params) -> ret {
/* self has type &T */
}
}
"Categories"
struct T<...> {
member1: T1;
mutable member2: T2;
priv member3: T3;
}
"Categories"
iface animal {
fn speak();
fn play();
};
Interfaces
class monster {
let mut health: int;
let name: str;
new(health: int, name: str) {
self.health = health;
self.name = name;
}
}
Classes
use std;
fn main(args: [str]) {
std::io::println("hello from '"
+ args[0]
+ "', world!");
}
Hello World
#warn("only %d seconds remaining", 10);
#error("fatal: %s", get_err_string());
Macros
fn call_twice(f: block()) { f(); f(); }
call_twice({|| "I am a block"; });
call_twice(fn@() { "Boxed closure"; });
fn bare_function() { "Plain function"; }
call_twice(bare_function);
Closures
alt mypoint {
{x: 0f, y: y_name} { /* Sub-pattern */ }
{x, y} { /* Bind */ }
}
Matching
let x = @10; // New box, refcount of 1
let y = x; // Copy pointer, bump refcount
Garbage-collected data
let x = ~10;
let y <- x;
Owned data