Last active
August 29, 2015 14:26
-
-
Save muja/ef17155a2284176c8b3c to your computer and use it in GitHub Desktop.
This file contains 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
fn main() { | |
extern "C" fn callback(msg: c_uint, user_data: c_long, p1: c_long, p2: c_long) -> c_int { | |
let ptr = p1 as *const _; | |
// turn information into a Rust String | |
let information = str::from_utf8(unsafe { CStr::from_ptr(ptr) }.to_bytes()).unwrap(); | |
// get user_data (our passed String): | |
let our_string = str::from_utf8(unsafe { slice::from_raw_parts(user_data as *const u8, 1024) } ).unwrap(); | |
// write information to our_string here... | |
} | |
let user_data = String::with_capacity(1024); | |
native_c_function(callback, user_data.as_ptr()); | |
println!("{}", user_data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment