Skip to content
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

what a some scenarios where such interoperability could be useful? #1

Closed
shengchl opened this issue Nov 23, 2021 · 5 comments
Closed

Comments

@shengchl
Copy link

Hey, just been wandering here and there when i landed on this project. This questions is out of pure curiosity as I am mostly a jr. programmer but rust<->swift interoperability looks like kind of exotic thing. I see that for both rust and swift its important to have access to the legacy of c world, but what are I some potential real world scenarios where swift-rust interop is a thing?

Just to make things clear - I am genuinely asking and appreciate the work done on this project!

@Brendonovich
Copy link
Owner

Hey, thanks for asking! To your point I haven't documented why you may want to use swift-rs, but I can tell you why I created it initially, which should answer your question.

I was helping my friend Jamie Pine with one of projects, which is a desktop app made with Tauri, an Electron alternative that uses Rust as its backend. One of the features Jamie wanted was to get the preview icon for files on his filesystem, which can be done with the icon(forFile:) function on the app's NSWorkspace. This requires accessing the static shared property of NSWorkspace, something that after some research wasn't possible using the Rust Objective-C bindings (since from what I can tell it only supports sending and receiving messages, not accessing static properties), and I could figure out if swift-bindgen could do the job. So I created this library and the rest is history!

The examples folder is actually the same Swift code that Jamie uses in his project. While there's probably other, less unsafe ways to interop with Swift, its been both my and Jamie's experience that leveraging Swift for it's native API access and Rust for building applications is quite nice compared to wrangling Swift with calls from Rust similar to how the objc crate has you do. This library probably has a littany of problems around memory management and leaks since I'm not that well versed in the Swift runtime, but it gets the job done where needed!

@Brendonovich
Copy link
Owner

@shengchalover I'm going to close this issue but feel free to keep commenting if you have any further questions

@shengchl
Copy link
Author

Thank you very much for detailed response. This is indeed a very interesting example of language interoperability!

@tleyden
Copy link

tleyden commented Jan 6, 2024

@Brendonovich

This library probably has a littany of problems around memory management and leaks

This comment was written a few years ago, just wondering if swift-rs is considered stable at this point?

@Brendonovich
Copy link
Owner

@tleyden Stable enough that Spacedrive hasn't experienced any problems and Tauri are using it for their iOS support.
There's been some pretty big changes since that comment was written, and the way swift-rs manages memory is predictable enough to where I'd be confident recommending it to other people.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants