Configuration
The generated Kotlin modules can be configured using a uniffi.toml
configuration file.
Available options
Configuration name | Default | Description |
---|---|---|
package_name |
uniffi |
The Kotlin package name - ie, the value used in the package statement at the top of generated files. |
cdylib_name |
uniffi_{namespace} [^1] |
The name of the compiled Rust library containing the FFI implementation (not needed when using generate --library ). |
generate_immutable_records |
false |
Whether to generate records with immutable fields (val instead of var ). |
custom_types |
A map which controls how custom types are exposed to Kotlin. See the custom types section of the manual | |
external_packages |
A map of packages to be used for the specified external crates. The key is the Rust crate name, the value is the Kotlin package which will be used referring to types in that crate. See the external types section of the manual | |
android |
false |
Used to toggle on Android specific optimizations |
android_cleaner |
android |
Use the android.system.SystemCleaner instead of java.lang.ref.Cleaner . Fallback in both instances is the one shipped with JNA. |
Example
Custom types
# Assuming a Custom Type named URL using a String as the builtin.
[bindings.kotlin.custom_types.Url]
# Name of the type in the Kotlin code
type_name = "URL"
# Classes that need to be imported
imports = [ "java.net.URI", "java.net.URL" ]
# Functions to convert between strings and URLs
into_custom = "URI({}).toURL()"
from_custom = "{}.toString()"
External types
[bindings.kotlin.external_packages]
# This specifies that external types from the crate `rust-crate-name` will be referred by by the package `"kotlin.package.name`.
rust-crate-name = "kotlin.package.name"