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

Add support for opaque Copy types #63

Merged
merged 1 commit into from Apr 24, 2022
Merged

Add support for opaque Copy types #63

merged 1 commit into from Apr 24, 2022

Conversation

chinedufn
Copy link
Owner

@chinedufn chinedufn commented Apr 24, 2022

This commit introduces a #[swift_bridge(Copy(...))] attribute that can
be used to indicate that an opaque Rust type should be passed across the
FFI boundary via a copy instead of by boxing it.

For example, the following is now possible:

#[swift_bridge::bridge]
mod ffi {
    extern "Rust" {
        #[swift_bridge(Copy(16))]
        type UserId;

        #[swift_bridge(Copy(16))]
        type OrganizationId;
    }
}

use uuid:Uuid;

#[derive(Copy)]
struct UserId(Uuid);

#[derive(Copy)]
struct OrganizationId(Uuid);

This commit introduces a `#[swift_bridge(Copy(...))]` attribute that can
be used to indicate that an opaque Rust type should be passed across the
FFI boundary via a copy instead of by boxing it.

For example, the following is now possible:

```rust
mod ffi {
    extern "Rust" {
        #[swift_bridge(Copy(16))]
        type UserId;

        #[swift_bridge(Copy(16))]
        type OrganizationId;
    }
}

use uuid:Uuid;

\#[derive(Copy)]
struct UserId(Uuid);

\#[derive(Copy)]
struct OrganizationId(Uuid);
```
@chinedufn chinedufn merged commit 607e305 into master Apr 24, 2022
@chinedufn chinedufn deleted the opaque-copy branch April 24, 2022 04:43
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