swift-bridge icon indicating copy to clipboard operation
swift-bridge copied to clipboard

Support methods on `Transparent Enum`

Open NiwakaDev opened this issue 2 years ago • 1 comments

I guess that swift-bridge doesn't support methods on Transparent Enum yet, like so:

#[swift_bridge::bridge]
mod ffi {
    enum SomeEnum {
        Variant1,
        Variant2
    }
    extern "Rust" {
        #[swift_bridge(self = SomeEnum)]
        fn some_function(&self);
    }
}

NiwakaDev avatar Mar 10 '23 03:03 NiwakaDev

Good idea. This would be really useful.

I'm thinking instead of a #[swift_bridge(self = SomeEnum) we could instead do fn some_function(self: &SomeEnum).

This would be consistent with the self: &MyOpaqueType syntax that we use for opaque types, for example: https://github.com/chinedufn/swift-bridge/blob/4f2a9d70ceabfae1708628bb637c7ba0ac9225d7/crates/swift-bridge-ir/src/codegen/codegen_tests/extern_rust_method_swift_class_placement_codegen_tests.rs#L13-L30


I'm also thinking that, at least to start, we'd want to only support an owned self: SomeEnum, since we don't currently support passing transparent enums by reference (I personally haven't thought about the best way to pass enum references between languages).

chinedufn avatar Mar 10 '23 04:03 chinedufn