Last active
August 29, 2015 14:12
-
-
Save zargony/1099e61966b5fc7285c2 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
#![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