This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn add_one(n: int) ⟶ int { | |
n + 1 | |
} | |
fn times_two(n: int) ⟶ int { | |
n * 2 | |
} | |
fn chain<A,B,C>(f1: ~fn(a: A) ⟶ B,f2: ~fn(b: B) ⟶ C) ⟶ ~fn(A) ⟶ C { | |
|x: A| { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use core::from_str::*; | |
fn stringify<T: ToStr>(x: T) ⟶ ~str { | |
x.to_str() | |
} | |
fn unstringify<T: FromStr> (s: ~str) ⟶ Option<T> { | |
FromStr::from_str(s) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use core::from_str::*; | |
fn stringify<T: ToStr>(x: T) -> ~str { | |
x.to_str() | |
} | |
fn unstringify<T: FromStr> (s: ~str) -> Option<T> { | |
FromStr::from_str(s) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
fn empty_vec<T>() -> ~[T] { | |
let v: ~[T] = ~[]; | |
v | |
} | |
fn main() { | |
let mut v_int = empty_vec<int>(); | |
let mut v_float = empty_vec<float>(); | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use std::libc::size_t; | |
static LONG: int = 0; | |
static OBJECTPOINT: int = 10_000; | |
static FUNCTIONPOINT: int = 20_000; | |
static OFF_T: int = 30_000; | |
macro_rules! CINIT( | |
($name:ident $typ:ident $val:expr) => ( | |
$name = $typ + $val |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#[deriving(Eq,Rand)] | |
pub enum Card { | |
One = 1, | |
Two, | |
Three, | |
Four, | |
Five, | |
Six, | |
Seven, | |
Eight, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// listen.rs | |
use extra::net::ip; | |
use extra::net::tcp; | |
use std::task; | |
pub fn server_loop() { | |
use extra::uv::iotask::spawn_iotask; | |
let mut builder = task::task(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// mummy.rs | |
use pc::PC; | |
use common::{Character}; | |
#[deriving(ToStr)] | |
pub struct Mummy { | |
hp: uint, | |
attack: uint, | |
x: int, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// traitfail.rs | |
trait Slide { | |
fn new(x: int) -> Self; | |
fn x_mut<'r> (&'r mut self) -> &'r mut int; | |
fn x(&self) -> int; | |
} | |
struct Bead { | |
x: int |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// curl/opt.rs | |
macro_rules! CINIT( | |
($name:ident, $typ:expr, $val:expr) => ( | |
$name = $typ + $val, | |
) | |
) | |
static LONG: i32 = 0i32; |
OlderNewer