Skip to content

Instantly share code, notes, and snippets.

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> {
use core::either::{Left, Either};
fn main() {
let f : Either<uint, uint> = Left(3);
}
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);
struct Foo { f: int }
impl Foo {
fn bar(&self) {}
}
fn foo(_: &Foo) {
}
fn main() {
fn main() {
let a = ~[~1];
for a.each |&b| {
// b is a copy of the owned box
}
}
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();
}
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?
(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
mod a {
pub type b = int;
}
mod b {
use a; // bad
use a::b; // good
}
struct MyStruct(int);
fn main() {
let b = MyStruct(3);
let mut MyStruct(a) = b;
a += 3;
io::println(fmt!("%d\n", a));
}