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

Support failable initializers #276

Closed NiwakaDev closed 1 month ago

NiwakaDev commented 3 months ago

Related to #235.

This PR supports failable initializers.

Something like:

// Rust side
#[swift_bridge::bridge]
mod ffi {
    extern "Rust" {
        #[swift_bridge(Equatable)]
        type FailableInitType;

        #[swift_bridge(init)]
        fn new() -> Option<FailableInitType>;
    }
}
// Swift side
let failableInitType = FailableInitType()
if failableInitType == nil {
    ~
} else {
   ~
}

See: Swift Documentation - Failable Initializers

chinedufn commented 3 months ago

My feedback was minor, so feel free to Squash and merge after you address it.

When you Squash and merge remember to paste in your PR body as the commit message.


Alternatively you can rebase into a single commit, force push that, and then merge that. But Squash and merge essentially does the same thing.

chinedufn commented 2 months ago

Hello, hello. Still planning to land this?

NiwakaDev commented 2 months ago

Sorry. I'll address your review this weekend if possible.