-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support bridging Vec<TransparentStruct>
#305
Comments
We haven't implemented support for bridging Here's where we support swift-bridge/crates/swift-bridge-ir/src/codegen/generate_rust_tokens/shared_enum.rs Lines 161 to 166 in 53b93f4
The reason that being able to copy the For instance, the the Swift and Rust side can't currently share instances of #[swift_bridge::bridge]
mod ffi {
struct Foo { inner: String }
enum Bar { Variant(String) }
} The reason that we would need support for passing references to Without support for referencing elements in the vec then all you can do is add or remove elements to the vec. That would actually be useful in your case, since all you want to do is remove all the elements from the But, a complete design will require supporting methods like So, full support of bridging vecs that contained We have not yet explored sharing references to When we explore and solve that (assuming there's a good solution) that'll unlock Swift 6 has a lot of new ownership features, so there may be good ways to support sharing references to I don't know whether this is possible. I'll have to study some of the concurrency related Swift evolution documents to figure out the best path forward, if there is one. https://github.com/swiftlang/swift-evolution You may wish to subscribe to #155 which tracks our work on Rust+Swift ownership.
One temporary solution would be to pass your struct as an opaque type. We support bridging #[swift_bridge::bridge]
mod ffi {
extern "Rust" {
struct Thing;
fn get_things() -> Vec<Thing>;
}
} |
Vec<TransparentStruct>
Hi again :)
I'm running into an issue and wonder if I'm missing something or if this is by design. I have an array of transparent structs that I'd like to return to Swift. I'd be fine with returning a RustVec, but eventually I want a Swift array of FfiThings structs.
Right now my setup looks like this...
While the above works fine from a Rust perspective... when I compile Swift the return type is RustVec which doesn't compile because
FfiThing
isn't vectorizeable. This makes sense to me, since RustVecs are shallow views into Rust, and I want to copy FfiThing over to Swift.Do you have a recommended path here? Is there a way, for example, to tell the swift-bridge that I want an Array in Swift and not a RustVec? The array and structs in question will be read frequently from Swift, so I really do just want to copy all the data over to Swift rather than repeatedly call into Rust.
The text was updated successfully, but these errors were encountered: