Closed metasim closed 3 months ago
Yep, something like this should work:
#[cxx::bridge]
mod ffi {
unsafe extern "C++" {
include!("example/include/metasim.h");
type Type = crate::Type;
fn metasim() -> Type;
}
}
#[derive(Debug)]
#[repr(transparent)]
pub struct Type(std::ffi::c_int);
unsafe impl cxx::ExternType for Type {
type Kind = cxx::kind::Trivial;
type Id = cxx::type_id!("Type");
}
fn main() {
println!("{:?}", ffi::metasim());
}
Wow! Perfect... and simple! Thank you 🙏
I have a situation where there's a fairly complex C++ enum (below) I wish to be able to return to Rust as Opaque, but by value. IOW, I'd like to mark the type as
cxx::kind::Trivial
, but don't want a) to duplicate the definition as a shared type, or b) wrap it in aUniquePtr
. Is this at all possible with the current cxx?enum class Type