resources/samples/rust
use std;
/* Factorial */
fn fac(n: int) -> int {
let s: str = "This is
a multi-line string.
It ends with an unescaped '\"'.";
let c: char = 'ะค';
let r: str = r##" raw string "##;
let result = 1, i = 1;
while i <= n { // No parens around the condition
result *= i;
i += 1;
}
ret result;
}
pure fn pure_length<T>(ls: list<T>) -> uint { /* ... */ }
type t = map::hashtbl<int,str>;
let x = id::<int>(10);
// Define some modules.
#[path = "foo.rs"]
mod foo;
impl <T> Seq<T> for [T] {
fn len() -> uint { vec::len(self) }
fn iter(b: fn(T)) {
for elt in self { b(elt); }
}
}
enum list<T> {
Nil;
Cons(T, @list<T>);
}
let a: list<int> = Cons(7, @cons(13, @nil));
struct Baz<'a> {
baz: &'a str,
}
'h: for i in range(0,10) {
'g: loop {
if i % 2 == 0 { continue 'h; }
if i == 9 { break 'h; }
break 'g;
}
}