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
[package] | |
name="bob" | |
version="0.0.1" | |
authors=["insaneinside"] | |
[lib] | |
name="bob" | |
path="lib.rs" |
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(PartialEq)] | |
enum Ordering { | |
Less, | |
Equal, | |
Greater, | |
} | |
fn cmp(a: int, b: int) -> Ordering { | |
if a < b { Less } | |
else if a > b { Greater } |
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
pub enum Thing { | |
A(~Foo) | |
} | |
pub trait Foo {} | |
pub struct Struct; | |
impl Foo for Struct {} |
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 main() { | |
let numbers = [1, 2, 3]; | |
let keys = ["foo", "bar", "baz"]; | |
for (index, (&number, &key)): iter::enumerate(iter::zip(numbers, keys)) { | |
io::println(fmt!("%u: %s => %d", index, key, number)); | |
} | |
} |
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 main() { | |
let numbers = [1, 2, 3]; | |
let keys = ["foo", "bar", "baz"]; | |
for iter::zip(numbers, keys) |&number, &key| { | |
io::println(fmt!("%s => %d", key, number)); | |
} | |
for iter::enumerate(keys) |&index, &key| { | |
io::println(fmt!("%u => %s", index, key)); |
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
/* a macro that defines a context variable that is stored in thread local | |
storage. It's implemented as a module that exports a `get`, `set` and | |
`set_to` function. `set_to` acts as a stack. */ | |
macro_rules! _context_var_impl (($name:ident : $t:ty, $primer:expr, $is_primed:expr) => ( | |
mod $name { | |
/* internal tls key helper */ | |
fn key(_x: @$t) {} | |
/* primes a context variable from a callback */ | |
fn prime(f: fn() -> @$t) -> @$t { |
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
/* | |
* This is a first attempt at dynamic Rust channels | |
* | |
* Paul Harvey | |
* 8 jan 2013 | |
*/ | |
//This should be replaced by generics | |
enum Msg_Type{ | |
integer, |
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 foo(a: Option<int>, b: Option<int>, c: Option<int>) { | |
arg_fail!( in "foo" | |
if matches!(a: None) : "a missing"; | |
if matches!(b: Some(_)) : "Don't need b"; | |
if matches!(b: None) && matches!(c: None) : "Need neither b nor c"; | |
) | |
... | |
} |
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
struct A { | |
v :~[int], | |
} | |
impl A { | |
fn foo(&mut self) { | |
//error: illegal borrow unless pure: unique value in aliasable, mutable location | |
let pa = &mut self.v[1]; | |
//note: impure due to assigning to dereference of mutable & pointer | |
*pa = 5; |
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
trait A {} | |
impl ~[int] : A {} | |
fn foo()-> A { | |
~[0] | |
} |
NewerOlder