fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.
https://fzyzcjy.github.io/flutter_rust_bridge/
MIT License
4.22k stars 290 forks source link

Let RustOpaque Expose the Arc #988

Closed anlumo closed 1 year ago

anlumo commented 1 year ago

Is your feature request related to a problem? Please describe.

Working with async code (via Streams) with this project means that I have to keep objects around even after the function call itself returns. Due to the ownership rules of Rust, I have to use something like Arc for this, because both my closure and Dart have to keep a reference to that object around and lifetimes are not transferred over the bridge. RustOpaque is already halfway there by using an Option<Arc<_>> internally. However, the Rust code doesn't have access to that field.

Describe the solution you'd like

RustOpaque should implement a function that returns a clone of the inner Arc.

Describe alternatives you've considered

It's possible to do it right now by using an Arc as part of the type wrapped by RustOpaque, but then it's an unnecessary double-Arc.

Additional context

The PR is incoming, this ticket is just there because you require one for the PR.

fzyzcjy commented 1 year ago

It's possible to do it right now by using an Arc as part of the type wrapped by RustOpaque, but then it's an unnecessary double-Arc.

Totally agree that we should not have double arc if avoidable. (have cc in the PR)

stale[bot] commented 1 year ago

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

anlumo commented 1 year ago

👀

github-actions[bot] commented 1 year ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new issue.