### Quick Start: eqswift setup and Swift binding generation Source: https://docs.rs/eqswift/latest/eqswift Quick start example: annotate Rust items with eqswift macros, then build and generate Swift bindings. The Rust block shows setup, export, Record, Object, and constructor detection. The command block shows the required build and binding generation steps. ```rust 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 { // Automatically detected as constructor — no attribute needed pub fn new() -> Self { Self } pub fn greet(&self, name: String) -> String { format!("Hello, {name}!") } } ``` ```bash cargo build cargo eqswift swift --out-dir swift/Generated ``` -------------------------------- ### Usage of eqswift::setup! with export Source: https://docs.rs/eqswift/latest/eqswift/macro.setup.html Example of calling setup! once at the top of the crate root before exporting items with #[eqswift::export]. ```rust eqswift::setup!(); #[eqswift::export] pub fn add(a: u32, b: u32) -> u32 { a + b } ``` -------------------------------- ### eqswift::setup!() and #[eqswift::export] Quick Start Source: https://docs.rs/eqswift Complete Rust source for a minimal eq-swift project. Call `eqswift::setup!()` once at the top of `lib.rs`, then annotate functions with `#[eqswift::export]` and derive `Record`, `Object`, `Enum`, or `Error` as needed. The `Greeter` constructor is auto-detected without an attribute. ```rust 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 { // Automatically detected as constructor — no attribute needed pub fn new() -> Self { Self } pub fn greet(&self, name: String) -> String { format!("Hello, {name}!") } } ``` -------------------------------- ### setup! macro signature Source: https://docs.rs/eqswift/latest/eqswift/macro.setup.html Shows the proc-macro signature of the setup! macro. ```rust setup!() { /* proc-macro */ } ``` -------------------------------- ### lib.rs source: full implementation Source: https://docs.rs/eqswift/latest/src/eqswift/lib.rs.html The complete source code of the eqswift crate's lib.rs, showing re-exports, setup, and example exported items. It includes a `Person` record, a `Greeter` object with a constructor and methods, and free functions `add` and `version`. ```rust //! eq-swift — Zero-config Rust-to-Swift FFI //! //! A thin, ergonomic wrapper around [UniFFI](https://github.com/mozilla/uniffi-rs) //! 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 //! //! ```ignore //! 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 { //! // 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: //! ```bash //! cargo build //! cargo eqswift swift --out-dir swift/Generated //! ``` //! //! # Macros //! //! | Macro | Purpose | //! |-------|---------| //! | [`setup!`](eqswift_macros::setup) | One-time initialization. Call once at the top of `lib.rs`. | //! | [`export`](eqswift_macros::export) | Mark a free function or `impl` block for export. Auto-detects constructors. | //! | [`Record`](uniffi::Record) | Derive for plain data structs (Swift `struct`). | //! | [`Object`](uniffi::Object) | Derive for reference types with methods (Swift `class`). | //! | [`Enum`](uniffi::Enum) | Derive for enums. | //! | [`Error`](uniffi::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]` | //! | `Option` | `T?` | //! | `Result` | `throws` | //! //! See the [UniFFI type docs](https://mozilla.github.io/uniffi-rs/latest/types/builtin_types.html) //! for the complete list. pub use eqswift_macros::{export, setup}; pub use uniffi::Enum; pub use uniffi::Error; pub use uniffi::Object; pub use uniffi::Record; #[doc(hidden)] pub use uniffi::constructor as __uniffi_constructor; #[doc(hidden)] pub use uniffi::export as __uniffi_export; #[doc(hidden)] pub use uniffi::setup_scaffolding; extern crate self as eqswift; eqswift::setup!(); /// A simple data record exported to Swift as a `struct`. #[derive(eqswift::Record)] pub struct Person { pub name: String, pub age: u32, } /// An object exported to Swift as a `class` with methods. #[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}!") } pub fn greet_person(&self, person: Person) -> String { format!("Hello, {}! You are {} years old.", person.name, person.age) } } #[eqswift::export] pub fn add(a: u32, b: u32) -> u32 { a + b } #[eqswift::export] pub fn version() -> String { env!("CARGO_PKG_VERSION").to_string() } ``` -------------------------------- ### Export an impl block with constructor using #[eqswift::export] and #[uniffi::constructor] Source: https://docs.rs/eqswift/latest/eqswift/attr.export.html For constructors inside exported impl blocks, use #[uniffi::constructor]. This example shows an exported impl block for a struct derived with eqswift::Object. ```rust #[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}!") } } ``` -------------------------------- ### Build and Generate Swift Bindings with cargo eqswift swift Source: https://docs.rs/eqswift Build the Rust crate and generate Swift bindings. Run `cargo build` first, then `cargo eqswift swift --out-dir swift/Generated` to produce the Swift interface files. ```bash cargo build cargo eqswift swift --out-dir swift/Generated ``` -------------------------------- ### Greeter Methods Source: https://docs.rs/eqswift/latest/eqswift/struct.Greeter.html Methods for the Greeter struct that can be called directly by users. ```APIDOC ## pub fn new() -> Self ### Description Creates a new instance of the `Greeter` struct. ### Method new ### Parameters None ### Returns - **Self** - A new `Greeter` instance. ``` ```APIDOC ## pub fn greet(&self, name: String) -> String ### Description Greets a person by name and returns a greeting string. ### Method greet ### Parameters - **name** (String) - Required - The name of the person to greet. ### Returns - **String** - A greeting message. ``` ```APIDOC ## pub fn greet_person(&self, person: Person) -> String ### Description Greets a person object and returns a greeting string. ### Method greet_person ### Parameters - **person** (Person) - Required - The person to greet. ### Returns - **String** - A greeting message. ``` -------------------------------- ### Export a simple function with #[eqswift::export] Source: https://docs.rs/eqswift/latest/eqswift/attr.export.html Use this attribute macro to export a function to foreign languages. It is a thin wrapper around #[uniffi::export]. ```rust #[eqswift::export] fn hello(name: String) -> String { format!("Hello, {name}!") } ``` -------------------------------- ### Enum derive macro usage Source: https://docs.rs/eqswift/latest/eqswift/derive.Enum.html Shows the syntax for deriving the Enum macro with the available #[uniffi] attribute. ```rust #[derive(Enum)] { // Attributes available to this derive: #[uniffi] } ``` -------------------------------- ### Error derive macro syntax Source: https://docs.rs/eqswift/latest/eqswift/derive.Error.html Shows the syntax for deriving the Error macro with the `#[uniffi]` attribute. ```rust #[derive(Error)] { // Attributes available to this derive: #[uniffi] } ``` -------------------------------- ### Person struct definition Source: https://docs.rs/eqswift/latest/eqswift/struct.Person.html Defines a simple data record with public fields `name` and `age`. This struct is exported to Swift as a `struct`. ```rust pub struct Person { pub name: String, pub age: u32, } ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.