Skip to content

Instantly share code, notes, and snippets.

@smvv
Last active December 19, 2015 10:49
Show Gist options
  • Select an option

  • Save smvv/5943633 to your computer and use it in GitHub Desktop.

Select an option

Save smvv/5943633 to your computer and use it in GitHub Desktop.
use std::vec;
struct Message;
impl Message {
pub fn with_ptr<T>(&self, f: &fn(*u8, uint) -> T) -> T {
unsafe {
let data = vec::raw::to_ptr([1 as u8]);
let len = 1 as uint;
f(data, len)
}
}
pub fn with_bytes<T>(&self, f: &fn(&[u8]) -> T) -> T {
do self.with_ptr |data, len| {
unsafe { vec::raw::buf_as_slice(data, len, f) } // <-- error
}
}
}
fn main () {
}
/*
test.rs:17:55: 17:56 error: cannot move out of captured outer variable
test.rs:17 unsafe { vec::raw::buf_as_slice(data, len, f) }
^
-- solution: --
test.rs:17 unsafe { vec::raw::buf_as_slice(data, len, |data| f(data)) }
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment