uniffi-rs
uniffi-rs copied to clipboard
Limitations around `#[uniffi::export(async_runtime = "tokio")]`
I just wanted to point out a use case I have that is not well supported.
Sometimes a function may, or may not require async_runtime = "tokio" depending what happens at runtime. There seems to be no way to conditionally require tokio with uniffi based on runtime considerations.
In my project, Im creating a struct Hyperbee. It can be backed by data either on disk, or in memory.
When the struct is created from data on disk, it uses tokio::fs to read from disk, so it needs tokio. When backed by memory, it doesn't need tokio.
This appeared in a somewhat surprising way, my tests were failing based on how my struct was constructed. Even after I marked just the constructor function with async_runitem = "tokio". Since the structs methods would read from disk when called.
The only solution I could think of was to just mark everything that could potentially require tokio with async_runtime = "tokio" so that is what I ended up doing. This works but seems less than optimal. I there is a better way please let me know!