swift-bridge
Call Rust from Swift and vice versa.
swift-bridge
generates code that helps you call Swift from Rust and vice versa.
swift-bridge
takes inspiration from the bridge module idea pioneered by cxx.
Current Status
swift-bridge
is not yet production ready.
We need to use it more before we can be confident enough in the generated FFI glue to call swift-bridge
production ready.
Right now I'm looking for feedback in order to continue to improve the APIs and the generated code.
I can especially use feedback from people with Swift experience, since I don't have much.
Installation
# In your Cargo.toml
[]
= "0.1"
[]
= "0.1"
Quick Peek
Here's a quick peek at how bindings look.
A more thorough walk through of swift-bridge
can be found in the book (TODO: Link to GitHub pages).
// lib.rs
TODO's before open sourcing
- Create a tutorial on setting up a project
Built-In Types
swift_bridge
comes with support for a number of Rust and Swift standard library types.
name in Rust | name in Swift | notes |
---|---|---|
u8, i8, u16, i16... etc | UInt8, Int8, UInt16, Int16 ... etc | |
bool | Bool | |
String, &String, &mut String | RustString | |
&str | RustStr | |
Vec | RustVec<T> | |
SwiftArray<T> | Array<T> | Not yet implemented |
&[T] | UnsafeBufferPointer<T> | |
&mut [T] | UnsafeMutableBufferPointer<T> | Not yet implemented |
SwiftString | String | |
Box | Not yet implemented | |
[T; N] | Not yet implemented | |
*const T | UnsafePointer<T> | |
*mut T | UnsafeMutablePointer<T> | |
Option<T> | Optional<T> | Currently only supports function return types that are primitive (i.e. -> Option<i32> ), or -> Option<String> .. More support will come. Other places such as function arguments are not yet implemented but will come. |
Result<T> | Not yet implemented | |
Have a Rust standard library type in mind? Open an issue! | ||
Have a Swift standard library type in mind? Open an issue! |
To Test
To run the test suite.
# Clone the repository
# Run tests
&&
See Also
- Rust on iOS
- A blog post by Mozilla that explains how to run Rust on iOS.