Functions
Functions are exposed in a namespace, either via UDL or proc-macros
#[uniffi::export] // if using proc-macros
fn hello_world() -> String {
"Hello World!".to_owned()
}
Note that everything described here applies to all "callables" - eg, interface methods, constructors etc.
Optional arguments & default values
You can specify a default value for function arguments (in UDL and proc-macros)
The Rust code will still take a required argument:
fn hello_name(name: String) -> String {
format!("Hello {}", name)
}
The generated foreign-language bindings will use function parameters with default values.
If the default argument value is "world"
, the generated Kotlin code will be equivalent to:
fun helloName(name: String = "world" ): String {
// ...
}
Async
Async functions "just work" with proc-macros, while UDL can use the [Async]
attribute:
See the Async/Future support section for details.