How to cast c_void to a string


#1

Hi,

How do I cast a *mut c_void to a string and do a println?

e.g:
extern fn callback(msg: *mut c_void, user_data: *mut c_void)
{
// save to string
// print out msg
}


#2
fn print(msg: *mut raw::c_void) {
    assert!(!msg.is_null());
    // to_string_lossy() returns a `Cow<str>`, but that's sufficient for printing.
    let cstr = unsafe {CStr::from_ptr(msg as *const _)}.to_string_lossy();
    println!("{}", cstr);
}

#3

Thank you! It’s working now!