For usage in Rust on how to use uniffi’s proc-macros, see the uniffi-rs book for Procedural Macros: Attributes and Derives.
This section is about how the generated Typescript maps onto the Rust idioms available.
A useful way of organizing this is via the types that can be passed across the FFI.
| Rust | Typescript | |
| Unsigned integers | u8, u16, u32 | number | Positive numbers only |
| Signed integers | i8, i16, i32 | number | |
| Floating point | f32, f64 | number | |
| 64 bit integers | u64, i64 | bigint | MDN |
| Strings | String | string | UTF-8 encoded |
| Rust | Typescript | |
| Byte array | Vec<u8> | ArrayBuffer | MDN |
| Timestamp | std::time::SystemTime | Date | aliased to UniffiTimestamp |
| Duration | std::time::Duration | number ms | aliased to UniffiDuration |
| Rust | Typescript | |
| Optional | Option<T> | T | undefined | |
| Sequences | Vec<T> | Array<T> | Max length is 2**31 - 1 |
| Maps | HashMap<K, V> BTreeMap<K, V> | Map<K, V> | Max length is 2**31 - 1 |
| Rust | Typescript | |
| Objects | struct Foo {} | class Foo | class objects with methods |
| Records | struct Bar {} | type Bar = {} | objects without methods |
| Error objects | struct Baz {} | Error | object is a property of the Error |