chinedufn / swift-bridge

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

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

Closed chinedufn closed 7 months ago

chinedufn commented 7 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.