mozilla / uniffi-rs

a multi-language bindings generator for rust
https://mozilla.github.io/uniffi-rs/
Mozilla Public License 2.0
2.89k stars 232 forks source link

Swift: invalid redeclaration of 'UniffiForeignFutureTask' #2310

Open QuentinPerez opened 2 weeks ago

QuentinPerez commented 2 weeks ago

👋 Hey there!

Looks like there’s a compilation issue with Swift when defining more than one async_trait. To help track it down, a small commit was made to reproduce the problem here. You can see it in action by running cargo test -p uniffi-fixture-multiple-definitions.

It turns out that defining this code only once seems to fix things:

// Protocol for tasks that handle foreign futures.
//
// Defining a protocol allows all tasks to be stored in the same handle map, 
// which isn’t doable with the task object itself because of its generic parameters.
protocol UniffiForeignFutureTask {
    func cancel()
}

extension Task: UniffiForeignFutureTask {}