-
Notifications
You must be signed in to change notification settings - Fork 347
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shared Type Question #330
Comments
Shared structs produce both a Rust definition and a C++ definition. If a C++ definition already exists, you can't use a shared struct for the same thing, but you can use an extern C++ type. #[repr(u8)]
pub enum SomeEnum {
A,
B,
C,
}
#[repr(C)]
pub struct Thing {
someenum: SomeEnum,
}
unsafe impl cxx::ExternType for Thing {
type Id = cxx::type_id!("Thing");
}
#[cxx::bridge]
mod ffi {
extern "C" {
type Thing = crate::Thing;
}
} |
That did the trick! Also, this is probably out of scope, but it looks like when rustfmt runs, the |
That is a rustfmt bug rust-lang/rustfmt#4159 which was fixed in rust-lang/rustfmt#4164 but has not been released yet (:slightly_frowning_face: for a long time). I've opened rust-lang/rustfmt#4447 to backport the fix to the current released version of rustfmt. For now you can either switch to rustfmt v2.0.0-rc.2 which contains the fix, or use #[rustfmt::skip]. |
I'll use the skip. Thanks! |
Hey, this may not be the right direction to go, but feel free to correct me.
I am wrapping a C++ library, and they've defined a struct like this:
I want to be able to directly access the struct with a Rust struct like this:
As a test, I've tried doing something like this:
But I'm probably misunderstanding how ExternType works.
Either way, is this (or something like this) possible to do in cxx currently (or will be possible in the near future)?
Thanks!
The text was updated successfully, but these errors were encountered: