Can a struct containing a raw pointer implement Send and be FFI safe?
问题 I have a scenario where Rust will call C to malloc a buffer and stash the resulting pointer into a struct. Later on, the struct will be moved to a thread and passed to a C function which mutates it. The naive approach to my problem looks like this (playground): extern crate libc; use libc::{c_void, malloc, size_t}; use std::thread; const INITIAL_CAPACITY: size_t = 8; extern "C" { fn mutate(s: *mut Storage); } #[repr(C)] struct Storage { #[allow(dead_code)] buf: *mut c_void, capacity: usize, }