According to the answer this question of mine: How to hold Rust objects in Rust code created through C++? I can pass back to C something allocated in Rust inside a Box
, and then receive it back again as a reference to &T
, because Rust allocates Sized
structs respecting the C ABI.
I want to do the same thing but now for Rc<RefCell<T>>
. Should I return a Box
to the Rc<RefCell<T>>
? My guess it no since Rc
does not implement Sized
, which is required for T
in Box<T>
according to the Box page. So this would not work:
#[no_mangle]
pub extern "C" fn foo_new() -> Box<Rc<RefCell<T>>> {
Box::new(Foo { glonk: false })
}
How can I make this work? Basically I need to create a Rust struct that can be accessed by many, and mutably borrowed by one of these many. That's why I choose Rc<RefCell<T>>
. Is there perhaps another type of structure that can do what I want and be C-friendly?