mozilla / uniffi-rs

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

Swift classes are not generated properly with their Protocol as Generic Type #2188

Closed pablogeek closed 2 months ago

pablogeek commented 2 months ago

I have this trait

#[uniffi::export]
pub trait PublicKey: Send + Sync {
    fn to_u8a(&self) -> Vec<u8>;
}

And then


#[derive(uniffi::Object)]
#[derive(Debug)]
struct Secp256r1 {
    pub bytes: Vec<u8>
}

#[uniffi::export]
impl PublicKey for Secp256r1 {
    fn to_u8a(&self) -> Vec<u8> {
        let mut vec = vec![Tag::Secp256r1.to_u8a()];
        vec.extend_from_slice(&self.bytes);
        vec
    }
}

but the swift class generated looks like this

public protocol Secp256r1Protocol: AnyObject {
    func toU8a() -> Data
}

open class Secp256r1:
    Secp256r1Protocol

Secp256r1 should implement PublicKey in swift too

How can I solve this?

mhammond commented 2 months ago

This looks the same as #2169?

pablogeek commented 2 months ago

yes looks like that. Closing it