-
Notifications
You must be signed in to change notification settings - Fork 13k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
better visibility control #3505
Comments
We actually worked reasonably hard to make it possible to simulate this via |
This has been a constant source of frustration for many months now (an example of how to structure a non-trivial library would be very helpful). The old model wasn't documented especially well and the new pub and priv stuff doesn't appear to be documented at all.
|
Reopening for @jesse99. I can certainly sympathize. Visibility and resolution rules have always been hazy, and even for 0.4 there's going to be a lot that isn't settled. I will note that crate level visibility is similar to the issue that the rust test driver has calling private tests, and the test runner actually has a super-secret attribute to allow it to break visibility rules to do it. |
This seems to be working as of rust 0.4. However wasn't able to fully test it because of #3781. |
I've been able to use stuff like However I still don't know how to a write an item that is visible within a crate but not outside of it. I can create a private sub-module and the parent module can control what is exported from the sub-module but afaict it's exported to everyone. Here's a motivating example. Fairly often I have some complex code with a very simple public API, often just a single function. I'd like to structure the code however I want. Maybe it's complex enough that I want to spread the implementation across multiple modules. Or maybe I want to split the code and unit tests into different modules. But as far as I know, I can't do any of this without making my implementation visible to everyone. Perhaps I am missing something but that is highly unsatisfactory. I really don't want to make my implementation details visible to clients, but I also really don't want to be forced into writing gargantuan modules. |
I apologize if I'm suggesting something you're already doing, but does this not do what you want?
|
I don't think so. It comes down to logical versus physical organization. From a logical standpoint the above is fine. But it doesn't seem to address the physical organization of the code (i.e. the files). |
I'm not feeling like we're going to change this. Reopen if you have a concrete proposal for change. |
Reopening. I would like the rule to be: "pub items in a non-pub mod are visible to the rest of the crate, but not visible to users outside the crate". This is necessary to finally seal the leakiness of the select trait abstraction, cf #5160. Hmm well, it's not strictly necessary, as all of the stuff that refers to what I wish to keep private could just be concatenated into the same file. But having it that way would mandate having enormous files which could otherwise be split apart. |
Yes, thank you. |
CI: don't run cron-fail-notify when the job just got canceled Doesn't seem right to prepare a PR in that case
It's very annoying that the only options for controlling visibility are public (to everyone) and private (to a module). C# has a nifty third option internal: (to an assembly).
If rust is moving towards using pub and priv to control visibility perhaps something like a crate keyword can be added so library authors have the freedom to structure their code as they like without being forced to make visible items which are properly of internal use.
The text was updated successfully, but these errors were encountered: