Created
February 29, 2012 05:33
-
-
Save nikomatsakis/1938225 to your computer and use it in GitHub Desktop.
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
enum deser = uint; | |
iface reader { | |
fn read_vec_elt<T:copy>(f: fn() -> T) -> T; | |
} | |
impl of reader for deser { | |
fn read_vec_elt<T:copy>(f: fn() -> T) -> T { | |
f() | |
} | |
} | |
fn read_to_vec<D:reader, T:copy>(self: D, f: fn() -> T) -> [T] { | |
let v = []; | |
self.read_vec_elt() {|| v += [f()] } | |
v | |
} | |
fn main() { | |
let x = deser(1u); | |
assert [22u] == read_to_vec(x) {|| 22u }; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment