Open PrismaPhonic opened 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.
look over the contributing docs https://github.com/chinedufn/swift-bridge/blob/master/book/src/contributing/adding-support-for-a-signature/README.md
adding a RustVecRef<T: Vectorizable>
and RustVecRefMut<T: Vectorizable>
here https://github.com/chinedufn/swift-bridge/blob/53b118d17f2f1a2922e969de528b99a2ffbc7dde/crates/swift-bridge-build/src/generate_core/rust_vec.swift#L1-L41
making RustVec<T: Vectorizable>
inherit from RustVecRefMut
which inherits from RustVecRef
, similar to this https://github.com/chinedufn/swift-bridge/blob/53b118d17f2f1a2922e969de528b99a2ffbc7dde/book/src/bridge-module/opaque-types/README.md?plain=1#L56-L71 https://github.com/chinedufn/swift-bridge/blob/53b118d17f2f1a2922e969de528b99a2ffbc7dde/crates/swift-bridge-ir/src/codegen/codegen_tests/opaque_rust_type_codegen_tests.rs#L36-L60
Add codegen tests for passing &Vec<T>
as an arg and as a return value, similar to these two https://github.com/chinedufn/swift-bridge/blob/53b118d17f2f1a2922e969de528b99a2ffbc7dde/crates/swift-bridge-ir/src/codegen/codegen_tests/vec_codegen_tests.rs#L177-L284
Add an integration test similar to the one for Vec<T>
https://github.com/chinedufn/swift-bridge/blob/53b118d17f2f1a2922e969de528b99a2ffbc7dde/SwiftRustIntegrationTestRunner/SwiftRustIntegrationTestRunnerTests/VecTests.swift#L79-L88
Get the tests passing by tweaking the codegen https://github.com/chinedufn/swift-bridge/blob/53b118d17f2f1a2922e969de528b99a2ffbc7dde/crates/swift-bridge-ir/src/bridged_type.rs#L48 https://github.com/chinedufn/swift-bridge/tree/53b118d17f2f1a2922e969de528b99a2ffbc7dde/crates/swift-bridge-ir/src/codegen
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
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?