-
Notifications
You must be signed in to change notification settings - Fork 374
Description
I've been working on introducing cxx to Fuchsia as a safer, better way for us to write Rust/C++ FFIs. As part of this, I'd like to provide a library or two with some common types for others to reuse in their own FFIs.
For example, see the handle types from #274; these would be a bridge between our C++ and Rust handle wrappers. These are important to write once and reuse because there's a lot of ways to implement them in a way that would cause resource leaks. Another example is a reusable Result type; we don't use exceptions and panicking on every error result is undesirable.
To do this, I'd like to be able to reuse shared types defined in one bridge module in another bridge module without having to treat them as opaque Rust types in the using module (so that they can be passed by value without boxing). Today these seem to just be recognized as unsupported types. For example:
// handle.rs
#[cxx::bridge(namespace = zx::ffi)]
mod ffi {
struct Process {
raw: u32,
}
struct Job {
raw: u32,
}
// ... and so on
}
impl Drop for ffi::Process { ... }
impl Drop for ffi::Job { ... }
// ... and so on, From impls to convert, etc.
// usage.rs
#[cxx::bridge(namespace = my_usage::ffi)]
mod ffi {
extern "Rust" {
fn create_process(name: &CxxString, job: &handle::ffi::Job) -> handle::ffi::Process;
}
}