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.29k stars 300 forks source link

Question on a `pub` fn/type inside a `pub(crate)` module #2256

Closed dbsxdbsx closed 3 months ago

dbsxdbsx commented 3 months ago

Frb v2.2, win10.

Suppose the api module rust\src\api\mod.rs is this:

//
// Do not put code in `mod.rs`, but put in e.g. `simple.rs`.
//
pub(crate) mod log;
pub mod api;

and there is struct or fn with prefix pub(crate) in log, then everything is fine, this logmodule is transparent to dart and frb. But if the struct or fn is prefixed with pub, then it is exposed to frb---But should it be visible or not?

I realize this issue when I lint fix rust code with this cmd:

cargo clippy --fix --allow-dirty --allow-staged --allow-no-vcs --all-targets -- -W clippy::all -W clippy::pedantic -W clippy::nursery -A clippy::missing_docs_in_private_items -A clippy::missing_inline_in_public_items -A clippy::redundant_pub_crate -A clippy::module_name_repetitions -A clippy::must_use_candidate ;

with removing -A clippy::redundant_pub_crate, after when rust automatically change mypub(crate) fn into pub fn in a pub(crate) module(log in this case).

So officially, Rust team thinks that anything inside a pub(crate) module would NOT surpass its visibility over its parent module---that is why pub is already enough inside a pub(crate) module. I wonder if frb should make the logic consistent to rust, though I am ok with the current logic.

fzyzcjy commented 3 months ago

Yes that looks reasonable. IIRC, frb does not strictly follow the semantics of pub of Rust, because the rules and all edge cases are somehow nontrivial. And fixing it will cause a breaking change (!), so we may consider this improvement in 3.0 version.

dbsxdbsx commented 3 months ago

Ok, then just leave it as it is now. Feel free to close.

fzyzcjy commented 3 months ago

Ok, no problem

github-actions[bot] commented 2 months 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.