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
pub mod graph { | |
use core::hashmap::linear::LinearMap; | |
pub type NodeId = uint; | |
pub struct Graph<N, E> { | |
priv nodes: LinearMap<NodeId, N>, | |
} | |
impl<N, E> Graph<N, E> { |
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 core::either::{Left, Either}; | |
fn main() { | |
let f : Either<uint, uint> = Left(3); | |
} |
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 core::hashmap::linear::LinearSet; | |
struct Foo { | |
n: LinearSet<int>, | |
} | |
impl Foo { | |
fn foo(&mut self, fun: fn(&int)) { | |
for self.n.each |f| { | |
fun(f); |
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 { f: int } | |
impl Foo { | |
fn bar(&self) {} | |
} | |
fn foo(_: &Foo) { | |
} | |
fn main() { |
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
fn main() { | |
let a = ~[~1]; | |
for a.each |&b| { | |
// b is a copy of the owned box | |
} | |
} |
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 { | |
thing: &int // errors don't happen unless this field is a borrowed pointer | |
} | |
impl Foo { | |
fn run(&mut self) { | |
self.foo(); | |
self.bar(); | |
} |
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
mod foo { | |
pub fn foo() {} | |
} | |
mod a { | |
pub mod b { | |
use foo::foo; | |
} | |
pub mod sub { | |
use a::b::*; | |
fn sub() { foo(); } // 'use foo::foo' in b wasn't 'pub', but this is ok? |
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
(gdb) disassemble | |
Dump of assembler code for function main: | |
=> 0x0000000100000f90 <+0>: mov $0x8,%al | |
0x0000000100000f92 <+2>: movsbl %al,%eax | |
End of assembler dump. | |
(gdb) stepi | |
0x0000000100000f92 in main () | |
(gdb) print $eax | |
$1 = 3848 | |
(gdb) stepi |
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
mod a { | |
pub type b = int; | |
} | |
mod b { | |
use a; // bad | |
use a::b; // good | |
} | |
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 MyStruct(int); | |
fn main() { | |
let b = MyStruct(3); | |
let mut MyStruct(a) = b; | |
a += 3; | |
io::println(fmt!("%d\n", a)); | |
} |