Skip to content

Instantly share code, notes, and snippets.

@zargony
Last active August 29, 2015 14:12
Show Gist options
  • Save zargony/1099e61966b5fc7285c2 to your computer and use it in GitHub Desktop.
Save zargony/1099e61966b5fc7285c2 to your computer and use it in GitHub Desktop.
#![feature(default_type_params)]
use std::thunk::Invoke;
struct Foo {
f: Box<for<'a> Invoke<&'a [u8]> + Send>,
}
impl Foo {
fn new<F> (f: F) -> Foo where F: FnOnce(&[u8]), F: Send {
Foo { f: box f }
}
fn foo (self) {
let data: [u8, ..4] = [1, 2, 3, 4];
let data_ref: &[u8] = data.as_slice();
self.f.invoke(data_ref);
}
}
fn main () {
let foo = Foo::new(|data| {
println!("Foo data: {}", data);
});
foo.foo();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment