fzyzcjy / flutter_rust_bridge

Flutter/Dart <-> Rust binding generator, feature-rich, but seamless and simple.

Home Page:https://fzyzcjy.github.io/flutter_rust_bridge/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Using StreamSink and RustOpaque in external crate

EddieMataEwy opened this issue · comments

Describe the bug

Now that in version 2 StreamSink and RustOpaque are in frb_generated.rs
How do we use them in external crates that are not in src/ or src/api ?
Before I could just import flutter_rust_bridge, but now?

Steps to reproduce

Have a local crate in /rust/ directory.
You can import the crate from /src/api by specifying the path in cargo.toml
Try to pass StreamSink, for example, to external crate function...

Logs

No logs

Expected behavior

No response

Generated binding code

No response

OS

No response

Version of flutter_rust_bridge_codegen

No response

Flutter info

No response

Version of clang++

No response

Additional context

No response

Firstly, I wonder whether it is best practice, e.g. should the external crate understand frb-specific things, or should be completely unaware of it in order to make the architecture more clear.

Secondly, in v2, usually you do not need to manually use RustOpaque, just write down arbitrary types, and frb will wrap the opaque for you automatically.

Thirdly, if you really want to use StreamSink here and there, there are some ways to solve this general issue of "suppose crate A depends on crate B, how to use crate A when inside crate B". For example, one way is to make a trait in crate B and make an impl in crate A.

You are welcome!

P.S. Alternatively to the channel, it is also possible to make a simple wrapper type, or make a simple closure, etc.

Yes. the closure is actually a lot better. Thank you!

You are welcome!

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.