chinedufn / swift-bridge

swift-bridge facilitates Rust and Swift interop.
https://chinedufn.github.io/swift-bridge
Apache License 2.0
810 stars 58 forks source link

Swift Option<String> and Option<&str> #264

Closed chinedufn closed 6 months ago

chinedufn commented 6 months ago

Swift Option and Option<&str>

This commit adds support for passing Option<String> to and from extern "Swift" functions, as well as for passing Option<&str> to extern "Swift" functions.

For example, the following is now possible:

#[swift_bridge::bridge]
mod ffi {
    extern "Swift" {
        fn opt_string_function(arg: Option<String>) -> Option<String>;

        fn opt_str_function(arg: Option<&str>);
    }
}

Note that you can not yet return -> Option<&str> from Swift.

This is an uncommon use case, so we're waiting until someone actually needs it.