fzyzcjy / flutter_rust_bridge

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

private field in external lib should mirror? #1904

Closed sealter closed 2 weeks ago

sealter commented 2 weeks ago

Sorry ask this stupid question, but I really don't know the answer.

I found the doc or example about struct mirror in external lib is all pub.

for example, I use PathBuf and reqwest::Client in my api struct and method (I reuse reqwest client for request, I wrapper it in my own struct, so I don't create it twice or more). I need mirror the struct, they all have private field, should I mirror them, or just the pub field?

Thank you.

fzyzcjy commented 2 weeks ago

I need mirror the struct, they all have private field, should I mirror them, or just the pub field?

If you want to use 3rd party types but do not need to access its field (I guess your case is like that), then just use the auto rust opaque feature. In other words, no need to do anything at all (no mirror etc), and it will be auto wrapped opaquely.

sealter commented 2 weeks ago

Oh, I see, I use builder pattern and make 3rd as param in pub build method. I modify the code remove it in param and it's OK now.

But I still want to know if it should mirror private field, if I can't modify the code, just like this case make it as param or return value of method or function, maybe others have the same doubt.

Thank you and thank you for your work, It's exellent.

fzyzcjy commented 2 weeks ago

You are welcome!

But I still want to know if it should mirror private field

I guess you will face errors no matter whether mirror it or ignore it, because the struct will not be able to be constructed directly.

sealter commented 2 weeks ago

OK, Thanks. I will close this issue.

Thank you very much.

fzyzcjy commented 2 weeks ago

You are welcome!

github-actions[bot] commented 5 days 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.