Pub, files, and container types

You may be right here, I may be misremembering reading that somewhere. And your explanation does match better with the lazy compilation behavior as well. So compilation unit may not be the right terminology to use here.

My experience is that maintainers often show bad judgement when given this ability. You have a struct, it has member functions, they can do things. There’s this idea “oh I’m the only one who will need to do this, right here”, which is what the implicit-protected rule allows, but I think this is more often wrong than not.

Purely internal functions make sense, what I don’t personally need, and don’t want because I’ve seen it cause problems, is a way to expose functionality only to blessed containers which happen to exist in the same file as the first. If a consumer of a struct can do something with it, that should be available everywhere IMHO. We’re not distributing object files, so all you’re doing is irritating someone who has to copy-paste a function out of your code.

Sometimes this is done out of a misguided conviction that anything marked pub has to be considered part of the public API, but that’s a convention, not a law of nature. There are better conventions worth adopting, but that’s somewhat of a separate conversation.

4 Likes