| 1 |
use std; |
| 2 |
|
| 3 |
#![warn(unstable)] |
| 4 |
|
| 5 |
/* Factorial */ |
| 6 |
fn fac(n: int) -> int { |
| 7 |
let s: str = "This is |
| 8 |
a multi-line string. |
| 9 |
|
| 10 |
It ends with an unescaped '\"'."; |
| 11 |
let c: char = 'ะค'; |
| 12 |
let r: str = r##" raw string "##; |
| 13 |
|
| 14 |
let result = 1, i = 1; |
| 15 |
while i <= n { // No parens around the condition |
| 16 |
result *= i; |
| 17 |
i += 1; |
| 18 |
} |
| 19 |
ret result; |
| 20 |
} |
| 21 |
|
| 22 |
pure fn pure_length<T>(ls: list<T>) -> uint { /* ... */ } |
| 23 |
|
| 24 |
type t = map::hashtbl<int,str>; |
| 25 |
let x = id::<int>(10); |
| 26 |
|
| 27 |
// Define some modules. |
| 28 |
#[path = "foo.rs"] |
| 29 |
mod foo; |
| 30 |
|
| 31 |
impl <T> Seq<T> for [T] { |
| 32 |
fn len() -> uint { vec::len(self) } |
| 33 |
fn iter(b: fn(T)) { |
| 34 |
for elt in self { b(elt); } |
| 35 |
} |
| 36 |
} |
| 37 |
|
| 38 |
enum list<T> { |
| 39 |
Nil; |
| 40 |
Cons(T, @list<T>); |
| 41 |
} |
| 42 |
|
| 43 |
let a: list<int> = Cons(7, @cons(13, @nil)); |
| 44 |
|
| 45 |
struct Baz<'a> { |
| 46 |
baz: &'a str, |
| 47 |
} |
| 48 |
|
| 49 |
'h: for i in range(0,10) { |
| 50 |
'g: loop { |
| 51 |
if i % 2 == 0 { continue 'h; } |
| 52 |
if i == 9 { break 'h; } |
| 53 |
break 'g; |
| 54 |
} |
| 55 |
} |