chinedufn / swift-bridge

swift-bridge facilitates Rust and Swift interop.
https://chinedufn.github.io/swift-bridge
Apache License 2.0
842 stars 62 forks source link

Is &Vec<T> supported? #261

Open PrismaPhonic opened 8 months ago

PrismaPhonic commented 8 months ago

I can't seem to get &Vec<T> to work - I looked through the swift rust bridge book at the type support table but don't see that one listed. Is it supposed to be supported yet?

chinedufn commented 8 months ago

No.

A temporary solution if you can afford a clone:

use std::clone::Clone;

#[swift_bridge::bridge]
mod ffi {
    #[swift_bridge(return_with = Clone::clone)]
    fn get_vec() -> Vec<String>;
}

fn get_vec() -> &Vec<String> {
    unimplemented!()
}

If you or a future person cannot use that workaround and need &Vec<T> support I would be happy to write up step by step hand-held instructions on how to add it. In the meantime that temporary workaround may help for non performance sensitive cases.




I'll leave a high-level summary of how to support it in case you or some future person ever needs &Vec<T> and cannot use the temporary workaround. If anyone sees this comment and wants more fine-grained hand-held instructions just let me know and I'll write them up.

PrismaPhonic commented 8 months ago

Thank you for the thoughtful reply. I'm pretty busy at the moment so will work around it - but if I get time in the future and it's not done yet I'll try to tackle it