Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Created February 29, 2012 05:33
Show Gist options
  • Save nikomatsakis/1938225 to your computer and use it in GitHub Desktop.
Save nikomatsakis/1938225 to your computer and use it in GitHub Desktop.
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