This file contains hidden or 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
#[feature(macro_rules)]; | |
use std::hashmap::HashMap; | |
macro_rules! lazy_init( | |
($(static ref $n:ident : $t:ty = $e:expr;)*) => ( | |
$( | |
struct $n; | |
impl $n { | |
#[allow(dead_code)] |
This file contains hidden or 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
struct Foo<'a> { | |
name: &'a str | |
} | |
impl<'a> Foo<'a> { | |
fn name(&'a mut self, s: &'a str) -> &'a mut Foo<'a> { | |
self.name = s; | |
self | |
} |
This file contains hidden or 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)] | |
struct ParamsBuilder { | |
foo: uint, | |
bar: ~str, | |
baz: uint, | |
run: bool | |
} | |
impl ParamsBuilder { |
This file contains hidden or 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
trait A {} | |
trait B {} | |
fn foo<t: A>() { | |
} | |
fn foo<t: B>() { |
This file contains hidden or 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
#[test] | |
fn test_iter(){ | |
let mut map = HashMap::<~str, uint>::new(); | |
map.insert(~"foo", 1); | |
map.insert(~"bar", 2); | |
let mut numbers = ~[]; | |
for (_k,v) in map.iter() { | |
numbers.push(v.clone()); | |
} |
This file contains hidden or 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::hashmap::HashMap; | |
#[test] | |
fn test_mangle(){ | |
let mut map = HashMap::<~str, uint>::new(); | |
assert!(!map.contains_key(&~"foo")); | |
map.mangle(~"foo", 1, | |
|_k, a| a + 10, | |
|_k, v, a| *v -= 2 |
This file contains hidden or 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::hashmap::HashMap; | |
#[test] | |
fn test(){ | |
let mut omap: Option<HashMap<~str, uint>> = None; | |
omap = Some(HashMap::new()); | |
let must_insert = false; | |
{ |
This file contains hidden or 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
#[ crate_id = "vmod_rpm#0.1" ]; | |
#[ crate_type = "dylib" ]; | |
// #[ no_std ]; | |
#[ allow(ctypes) ]; | |
extern mod extra; | |
use std::str; | |
use std::sync::atomics; | |
use std::sync::atomics::{ AtomicUint, AcqRel }; |
This file contains hidden or 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::sync::atomics::{ AtomicUint, INIT_ATOMIC_UINT, Ordering, AcqRel }; | |
static counter: AtomicUint = INIT_ATOMIC_UINT; | |
fn call() -> uint { | |
let current = counter.fetch_add(1, AcqRel); | |
current.clone() | |
} |
This file contains hidden or 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
#[ crate_id = "vmod_rpm#0.1" ]; | |
// #[ crate_type = "lib" ]; | |
#[ no_std ]; | |
// #[ allow(ctypes) ]; | |
// #[no_mangle] | |
// pub extern fn add(lhs: uint, rhs: uint) -> uint { | |
// lhs + rhs | |
// } |