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

derive(Debug) enum fixes #209

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

naturecodevoid
Copy link
Contributor

@naturecodevoid naturecodevoid commented Apr 7, 2023

  • fix: Add Debug to derived traits on Rust side even if one of the variants has data to hopefully avoid confusing the developer
  • fix: don't generate Debug functions in C header and Swift if any variants have data to avoid confusing the developer with undefined symbol build errors

Previously, this would cause a "undefined symbol" build error and cause the error not to implement Debug trait from Rust:

#[swift_bridge::bridge]
mod ffi {
    #[derive(Debug)]
    enum DeriveDebugEnum {
        Variant(String),
    }
}

When generating C headers and Swift, there was no check to ensure that the enum has no variants with data, but this check was added when generated Rust tokens. This causes undefined symbol if a variant has data since C and Swift thinks the method exists, but it actually doesn't.

This PR fixes the undefined symbol error and also makes the enum implement Debug, even if only from Rust.

@chinedufn
Copy link
Owner

Hey, thanks for working on this.

Mind updating your PR to more clearly explain the problem and how this PR solves the problem, as well as to include an example bridge module that illustrates what this PR enables?

Thanks!

@naturecodevoid
Copy link
Contributor Author

Added!

@naturecodevoid
Copy link
Contributor Author

naturecodevoid commented Oct 7, 2023

@chinedufn Sorry to bother you, but any chance of this being merged?

@NiwakaDev
Copy link
Collaborator

Can we add some tests?

@naturecodevoid
Copy link
Contributor Author

What tests need to be added?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants