-
Notifications
You must be signed in to change notification settings - Fork 62
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support opaque Swift types in results (#115)
This commit allows you to use opaque Swift types as the `Ok` or `Err` variant for a result. For example, the following is now possible: ```rust #[swift_bridge::bridge] mod ffi { extern "Swift" { type SomeSwiftType; fn some_function(arg: Result<(), SomeSwiftType>); } } ``` --- Along the way we introduced a `trait BridgeableType`. We're going to move the `enum BridgedType` with the `trait BridgeableType` over time.
- Loading branch information
Showing
34 changed files
with
2,002 additions
and
1,012 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
20 changes: 0 additions & 20 deletions
20
SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunner/Boolean.swift
This file was deleted.
Oops, something went wrong.
57 changes: 57 additions & 0 deletions
57
SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunner/Primitive.swift
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,57 @@ | ||
// | ||
// Primitive.swift | ||
// SwiftRustIntegrationTestRunner | ||
// | ||
// Created by Frankie Nwafili on 10/3/22. | ||
// | ||
|
||
import Foundation | ||
|
||
func swift_double_u8(arg: UInt8) -> UInt8 { | ||
arg * 2 | ||
} | ||
|
||
func swift_double_i8(arg: Int8) -> Int8 { | ||
arg * 2 | ||
} | ||
|
||
func swift_double_u16(arg: UInt16) -> UInt16 { | ||
arg * 2 | ||
} | ||
|
||
func swift_double_i16(arg: Int16) -> Int16 { | ||
arg * 2 | ||
} | ||
|
||
func swift_double_u32(arg: UInt32) -> UInt32 { | ||
arg * 2 | ||
} | ||
|
||
func swift_double_i32(arg: Int32) -> Int32 { | ||
arg * 2 | ||
|
||
} | ||
|
||
func swift_double_u64(arg: UInt64) -> UInt64 { | ||
arg * 2 | ||
} | ||
|
||
func swift_double_i64(arg: Int64) -> Int64 { | ||
arg * 2 | ||
} | ||
|
||
func swift_double_f32(arg: Float) -> Float { | ||
arg * 2.0 | ||
} | ||
|
||
func swift_double_f64(arg: Double) -> Double { | ||
arg * 2.0 | ||
} | ||
|
||
func swift_negate_bool(arg: Bool) -> Bool { | ||
!arg | ||
} | ||
|
||
func swift_reflect_null(arg: ()) -> () { | ||
arg | ||
} |
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
28 changes: 0 additions & 28 deletions
28
SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/BooleanTests.swift
This file was deleted.
Oops, something went wrong.
34 changes: 34 additions & 0 deletions
34
SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/PrimitiveTests.swift
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,34 @@ | ||
// | ||
// PrimitiveTests.swift | ||
// SwiftRustIntegrationTestRunnerTests | ||
// | ||
// Created by Frankie Nwafili on 10/3/22. | ||
// | ||
|
||
import XCTest | ||
@testable import SwiftRustIntegrationTestRunner | ||
|
||
/// Tests for generic types such as `type SomeType<u32>` | ||
class PrimitiveTests: XCTestCase { | ||
/// Run tests where Rust calls Swift functions that take primitive args. | ||
func testRustCallsSwiftPrimitives() throws { | ||
test_rust_calls_swift_primitives() | ||
} | ||
|
||
/// Run tests where Swift calls Rust functions that take primitive args. | ||
func testSwiftCallsRustPrimitives() throws { | ||
XCTAssertEqual(rust_double_u8(10), 20); | ||
XCTAssertEqual(rust_double_i8(10), 20); | ||
XCTAssertEqual(rust_double_u16(10), 20); | ||
XCTAssertEqual(rust_double_i16(10), 20); | ||
XCTAssertEqual(rust_double_u32(10), 20); | ||
XCTAssertEqual(rust_double_i32(10), 20); | ||
XCTAssertEqual(rust_double_u64(10), 20); | ||
XCTAssertEqual(rust_double_i64(10), 20); | ||
XCTAssertEqual(rust_double_f32(10.0), 20.0); | ||
XCTAssertEqual(rust_double_f64(10.0), 20.0); | ||
XCTAssertEqual(rust_negate_bool(true), false); | ||
XCTAssertEqual(rust_negate_bool(false), true); | ||
} | ||
} | ||
|
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
Oops, something went wrong.