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.

Simple scalar types

RustTypescript
Unsigned integersu8, u16, u32numberPositive numbers only
Signed integersi8, i16, i32number
Floating pointf32, f64number
64 bit integersu64, i64bigintMDN
StringsStringstringUTF-8 encoded

Other simple types

RustTypescript
Byte arrayVec<u8>ArrayBufferMDN
Timestampstd::time::SystemTimeDatealiased to UniffiTimestamp
Durationstd::time::Durationnumber msaliased to UniffiDuration

Structural types

RustTypescript
OptionalOption<T>T | undefined
SequencesVec<T>Array<T>Max length is 2**31 - 1
MapsHashMap<K, V>
BTreeMap<K, V>
Map<K, V>Max length is 2**31 - 1

Enumerated types

RustTypescript
EnumsenumenumFlat enums
Tagged Union Types)enumTagged unionsEnums with properties
Error enumsenumsError

Struct types

RustTypescript
Objectsstruct Foo {}class Fooclass objects with methods
Recordsstruct Bar {}type Bar = {}objects without methods
Error objectsstruct Baz {}Errorobject is a property of the Error