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

Return Result<OpaqueRust, OpaqueRust> #149

Merged
merged 1 commit into from
Jan 29, 2023
Merged

Return Result<OpaqueRust, OpaqueRust> #149

merged 1 commit into from
Jan 29, 2023

Conversation

chinedufn
Copy link
Owner

This commit makes it possible to return a
Result<OpaqueRust, OpaqueRust> from a Rust function.

Rust functions that return results show up on the Swift side as
functions that throw.

For example, the following is now possible:

// Rust

#[swift_bridge::bridge]
mod ffi {
    extern "Rust" {
        type TypeA;
        type TypeB;

        fn some_function() -> Result<TypeA, TypeB>;

        fn print_info(self: &TypeB);
    }
}
// Swift

do {
    let typeA = try some_function()
} catch let typeB as TypeB {
    typeB.print_info()
}

This commit makes it possible to return a
`Result<OpaqueRust, OpaqueRust>` from a Rust function.

Rust functions that return results show up on the Swift side as
functions that `throw`.

For example, the following is now possible:

```rust
// Rust

#[swift_bridge::bridge]
mod ffi {
    extern "Rust" {
        type TypeA;
        type TypeB;

        fn some_function() -> Result<TypeA, TypeB>;

        fn print_info(self: &TypeB);
    }
}
```

```swift
// Swift

do {
    let typeA = try some_function()
} catch let typeB as TypeB {
    typeB.print_info()
}
```
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 this pull request may close these issues.

None yet

1 participant