uniffi-rs icon indicating copy to clipboard operation
uniffi-rs copied to clipboard

Structs which `#[uniffi::export]` the impl of a trait should have that reflected in the bindings.

Open praveenperera opened this issue 1 year ago • 2 comments

I have the following trait

use crate::impl_default_for;

#[uniffi::export(with_foreign)]
pub trait AutoComplete: Send + Sync + std::fmt::Debug + 'static {
    fn autocomplete(&self, word: String) -> Vec<String>;
}

#[derive(Debug, Copy, Clone, uniffi::Object)]
pub struct Bip39AutoComplete;


#[uniffi::export]
impl Bip39AutoComplete {
    #[uniffi::constructor]
    pub fn new() -> Self {
        Self
    }
}

#[uniffi::export]
impl AutoComplete for Bip39AutoComplete {
    fn autocomplete(&self, word: String) -> Vec<String> {
        // todo: implement
        vec![]
    }
}

And this SwiftUI component

struct AutocompleteField<AutoCompleter: AutoComplete>: View {
    let autocompleter: AutoCompleter
    @Binding var text: String

   ...

But I can't automatically pass in Bip39AutoComplete into the SwiftUI component. To get it to work I have to do the following on the swift side.

extension Bip39AutoComplete: AutoComplete {}

It's not a big deal, just one line, but I was wondering if it could be added to the already generated code as below:

- open class Bip39AutoComplete: Bip39AutoCompleteProtocol {
+ open class Bip39AutoComplete: Bip39AutoCompleteProtocol, AutoComplete {

praveenperera avatar Jun 23 '24 21:06 praveenperera