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 setup!() call, no duplication.
Just annotate your items with #[eqswift::export] or #[derive(eqswift::Record)]
and build. The first #[eqswift::export] automatically initializes UniFFI.
Quick Start
#[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 {
// Automatically detected as constructor — no attribute needed
pub fn new() -> Self {
Self
}
pub fn greet(&self, name: String) -> String {
format!("Hello, {name}!")
}
}
Then build and generate Swift bindings:
Macros
| Macro | Purpose |
|---|---|
export |
Mark a free function or impl block for export. Auto-initializes UniFFI on first use. |
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. |
setup! |
Explicit initialization (optional, see export). |
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.