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

Add the ability to apply decorators to anonymous struct enum variants #149

Open
ahou8 opened this issue Nov 6, 2023 · 0 comments
Open

Comments

@ahou8
Copy link

ahou8 commented Nov 6, 2023

Consider the following enum decorated with the swift protocol Equatable.

#[typeshare(swift = "Equatable")]
#[serde(tag = "type", content = "content")]
enum MyEnum {
    MyVariant {
        a: String,
        b: f64
    }
}

Running this through typeshare, the following is generated

/// Generated type representing the anonymous struct variant `MyVariant` of the `MyEnum` Rust enum
public struct MyEnumMyVariantInner: Codable {
	public let a: String
	public let b: Double

	public init(a: String, b: Double) {
		self.a = a
		self.b = b
	}
}
public enum MyEnum: Codable, Equatable {
	case myVariant(MyEnumMyVariantInner)
       
        ...
}

Although Equatable was applied to MyEnum, it was not applied to MyEnumMyVariantInner. And there doesn't seem to be any way to do so.

My first thought was to apply #[typeshare(swift = "Equatable")] on the enum variant, but that was ignored.

#[typeshare(swift = "Equatable")]
#[serde(tag = "type", content = "content")]
enum MyEnum {
+  #[typeshare(swift = "Equatable")]
    MyVariant {
        a: String,
        b: f64
    }
}
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 a pull request may close this issue.

1 participant