-
Notifications
You must be signed in to change notification settings - Fork 64
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add attribute for Equatable protocol (#139)
This commit introduces the #[swift_bridge(Equatable)] attribute, which is used to generate a type that conforms to ```Equatable``` protocol. Somthing like: ```rust // Rust mod ffi { extern "Rust" { #[swift_bridge(Equatable)] type SomeType; } } ``` ```Swift // Generated Swift class SomeType { // ... } // SomeType inherits SomeTypeRef. So, SomeType also conforms to Equatable protocol. extension SomeTypeRef: Equatable { public static func == (lhs: SomeTypeRef, rhs: SomeTypeRef) -> Bool { __swift_bridge__$SomeTypeType$_partial_eq(rhs.ptr, lhs.ptr) } } ```
- Loading branch information
Showing
10 changed files
with
221 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
mod already_declared; | ||
mod copy; | ||
mod equatable; |
25 changes: 25 additions & 0 deletions
25
crates/swift-integration-tests/src/opaque_type_attributes/equatable.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#[swift_bridge::bridge] | ||
mod ffi { | ||
extern "Rust" { | ||
#[swift_bridge(Equatable)] | ||
type RustEquatableType; | ||
|
||
#[swift_bridge(init)] | ||
fn new() -> RustEquatableType; | ||
|
||
fn set_value(&mut self, value: i32); | ||
} | ||
} | ||
|
||
#[derive(PartialEq)] | ||
pub struct RustEquatableType(i32); | ||
|
||
impl RustEquatableType { | ||
fn new() -> Self { | ||
RustEquatableType(0) | ||
} | ||
|
||
fn set_value(&mut self, value: i32) { | ||
self.0 = value; | ||
} | ||
} |