uniffi-rs
uniffi-rs copied to clipboard
Setting a default for Duration type in proc macros
When deriving a uniffi::Record I have a few fields of type Duration and was hoping to give them a default value. However it seems at the moment the proc macros don't accept literals for it, despite durations being somewhat primitive types from the Built-in types table.
It would be great if the proc macros can be extended to accept expressions for Duration.
I only use Uniffi for Kotlin code, where there should be equivalents to construct the default value in a data class but I'm not sure if this is possible in other languages as well.
For Duration I'd imagine accepting the const constructors:
Duration::from_secsDuration::from_millisDuration::from_micros
And eventually:
Duration::from_secs_f32Duration::from_secs_f64
For example:
#[uniffi::Record]
struct Config {
#[uniffi(default = Duration::from_secs(5))]
max_wait: Duration,
}