Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![feature(unboxed_closures, core)]
- pub struct Foo<T> { t: T }
- impl<'a, T> Foo<T> where T: 'a + FnMut() -> &'a [u8] {
- pub fn from_callback(closure: T) -> Self {
- Foo { t: closure }
- }
- pub fn work(&mut self) {
- println!("{:?}", self.t.call_mut(()));
- println!("{:?}", self.t.call_mut(()));
- }
- }
- fn main() {
- let mut foo = {
- let buffer = vec![1, 2, 3, 4];
- let mut i = 0;
- Foo::from_callback(move || {
- let j = i;
- i += 1;
- &buffer[j..j+1]
- })
- };
- foo.work();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement