Skip to content
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

Enum with fields #63

Open
DBLouis opened this issue May 12, 2021 · 3 comments
Open

Enum with fields #63

DBLouis opened this issue May 12, 2021 · 3 comments
Labels
K-feature Kind: proposed new code to implement new behaviour
Milestone

Comments

@DBLouis
Copy link
Contributor

DBLouis commented May 12, 2021

Is it possible to add support for #[repr(C, Int)] enums?

In the Type layout reference it says:

The representation of a repr(C) enum with fields is a repr(C) struct with two fields, also called a "tagged union" in C

I am not sure is this is guaranteed tho. If it is we should be able to transmute both ways right?

Playground test: https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=fe82b419608d325d93481155c4458bc8

@danielhenrymantilla
Copy link
Collaborator

Indeed, that ought to be the implementation 👌 I am waiting on this since I'd like to bundle support for repr_c::Result from there, and I want to think a bit about the best design / layout (e.g., C ergonomics) for such a thing 🙂

@danielhenrymantilla danielhenrymantilla added K-feature Kind: proposed new code to implement new behaviour soon-ish labels May 12, 2021
@danielhenrymantilla danielhenrymantilla added this to the Version 0.1.0 milestone May 12, 2021
DBLouis added a commit to DBLouis/safer_ffi that referenced this issue May 12, 2021
@DBLouis
Copy link
Contributor Author

DBLouis commented May 12, 2021

I had a go at it but I'm stuck making the macro match all kinds of enums variants.

@danielhenrymantilla
Copy link
Collaborator

Yeah, I think this will require #46, the current situation with macro_rules! macros to save a bit of compile time is not worth the maintainability cost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
K-feature Kind: proposed new code to implement new behaviour
Projects
None yet
Development

No branches or pull requests

3 participants