Skip to main content

Crate eqswift

Crate eqswift 

Source
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

MacroPurpose
setup!One-time initialization. Call once at the top of lib.rs.
exportMark a free function or impl block for export. Constructors need #[uniffi::constructor].
RecordDerive for plain data structs (Swift struct).
ObjectDerive for reference types with methods (Swift class).
EnumDerive for enums.
ErrorDerive for error enums.

§Supported Types

Most Rust primitives map directly to Swift:

RustSwift
u32UInt32
i32Int32
f64Double
boolBool
StringString
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 class with methods.
Person
A simple data record exported to Swift as a struct.

Functions§

add
version

Attribute Macros§

export
Export a function, method, impl block, or trait to foreign languages.

Derive Macros§

Enum
Error
Object
Record