Last active
December 19, 2015 10:49
-
-
Save smvv/5943633 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
| 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