After scouring the internet some more, I found the answer here: Circumventing thread safety in rust with mutable pointers
And so, for my case, it looks like this:
pub struct TrblFile {
logicalFileName: *const ::std::os::raw::c_char,
opaque: *const ::std::os::raw::c_void,
}
// raw pointers are not thread-safe according to the compiler
// here we tell it thread-safety will be handled by us
unsafe impl Send for TrblFile {}
[...]
if let Some(cb) = storeCb {
let params = TrblFile { logicalFileName: copy_cstr(logicalFileName),
opaque: opaque };
let callback = Box::new(move || {
unsafe {
let result = cb(params.logicalFileName, params.opaque);
libc::free(params.logicalFileName as * mut c_void);
result
}
});
let mut callbacks = STORE_CALLBACKS.lock();
callbacks.push(callback);
}