uniffi-rs
uniffi-rs copied to clipboard
async functions defined in UDL can't throw errors
The patch below fails with:
error[E0599]: no method named `map_err` found for opaque type `impl Future<Output = Result<(), MyError>>` in the current scope
--> /Users/skip/src/moz/uniffi-rs/target/debug/build/uniffi-fixture-futures-9e0bccbae1fa25fc/out/futures.uniffi.rs:39:1
|
39 | #[::uniffi::export_for_udl]
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^ method not found in `impl Future<Output = Result<(), MyError>>`
This is almost certainly because we try and map_err for UDL here which doesn't do the right thing for async functions.
The patch:
diff --git a/fixtures/futures/src/futures.udl b/fixtures/futures/src/futures.udl
index 95d6e35fb..d15bcaa41 100644
--- a/fixtures/futures/src/futures.udl
+++ b/fixtures/futures/src/futures.udl
@@ -1,4 +1,9 @@
namespace futures {
[Async]
boolean always_ready();
+ [Async, Throws=MyError]
+ void never_ready();
};
+
+[Rust="enum"]
+typedef extern MyError;
diff --git a/fixtures/futures/src/lib.rs b/fixtures/futures/src/lib.rs
index 39a521495..ae06ea96c 100644
--- a/fixtures/futures/src/lib.rs
+++ b/fixtures/futures/src/lib.rs
@@ -74,6 +74,11 @@ pub async fn always_ready() -> bool {
true
}
+/// (Also defined in the UDL to test UDL error support)
+pub async fn never_ready() -> Result<(), MyError> {
+ Err(MyError::Foo)
+}
+
#[uniffi::export]
pub async fn void() {}