Hello list, Currently Rust has different default visibilities in different places: - `mod` items are private - `struct` fields and `enum` variants are public - `trait` methods are public - `impl` methods are private - `impls for` are public (by necessity)
I propose to change this to: - Everything not `priv` is public Points in favor: - It's much easier to explain, grok, and remember. - Most definitions are written to be public. Writing `public` in front of every dang thing was annoying in Java and C#, and it's no less annoying in Rust. Maybe especially so for those coming from C/C++, who haven't already resigned themselves to it. - Currently `impls for` are always public, while other items including `impl`s are private. This would make it consistent and remove a potential source of confusion. And instead of a deep-seated semantic rule for users to remember, there would be a simple syntactic one: you can't put `priv` on an `impl for`. - I get the reason for the `priv` default and requiring `pub` explicitly, and initially agreed with it: that module authors should think about what they export, therefore the burden should be on those cases where you want to make something public. But in my experience, module authors are very conscientious about their public interfaces, and put special importance on what should be kept hidden. Having this be explicit with `priv` isn't necessarily a disadvantage. - Reading a module for its interface won't be any worse: instead of looking for `pub`s and skipping things without it unless if they're `impls for`, you would read everything and skip the `priv`s. - The `pub` keyword could potentially be removed from the language. Issues: - Public by default clearly can't extend to `use`, which should remain private. That means `pub use` is left as an orphan. Either it could remain `pub`'s only use, or it could be expressed some other way. Thanks for considering, Gábor -- Your ship was destroyed in a monadic eruption.
_______________________________________________ Rust-dev mailing list [email protected] https://mail.mozilla.org/listinfo/rust-dev
