Expand description
eq-swift — Zero-config Rust-to-Swift FFI
A thin, ergonomic wrapper around UniFFI
that lets you write your entire foreign interface in Rust — no UDL files, no
build.rs, no duplication.
Just annotate your items with #[eqswift::export] or #[derive(eqswift::Record)],
call eqswift::setup!() once at the top of lib.rs, and build.
§Quick Start
ⓘ
eqswift::setup!();
#[eqswift::export]
pub fn add(a: u32, b: u32) -> u32 {
a + b
}
#[derive(eqswift::Record)]
pub struct Person {
pub name: String,
pub age: u32,
}
#[derive(eqswift::Object)]
pub struct Greeter;
#[eqswift::export]
impl Greeter {
#[uniffi::constructor]
pub fn new() -> Self {
Self
}
pub fn greet(&self, name: String) -> String {
format!("Hello, {name}!")
}
}Then build and generate Swift bindings:
cargo build
cargo eqswift swift --out-dir swift/Generated§Macros
| Macro | Purpose |
|---|---|
setup! | One-time initialization. Call once at the top of lib.rs. |
export | Mark a free function or impl block for export. Constructors need #[uniffi::constructor]. |
Record | Derive for plain data structs (Swift struct). |
Object | Derive for reference types with methods (Swift class). |
Enum | Derive for enums. |
Error | Derive for error enums. |
§Supported Types
Most Rust primitives map directly to Swift:
| Rust | Swift |
|---|---|
u32 | UInt32 |
i32 | Int32 |
f64 | Double |
bool | Bool |
String | String |
Vec<T> | [T] |
Option<T> | T? |
Result<T, E> | throws |
See the UniFFI type docs for the complete list.
Macros§
- setup
- One-time setup macro.
Structs§
- Greeter
- An object exported to Swift as a
classwith methods. - Person
- A simple data record exported to Swift as a
struct.
Functions§
Attribute Macros§
- export
- Export a function, method, impl block, or trait to foreign languages.