When imlementing non-private methods for a pub(crate)/pub(super) struct should they also be pub(crate)/pub(super) or just pub?

if I have some struct

pub(crate) struct Foo {
...
}

I can write

impl Foo {
    pub(crate) fn bar(&self) { ... }
}

But I could also safe a few letters and write

impl Foo {
    pub fn bar(&self) { ... }
}

and it'd be roughly equivalent as the ""public"" method can only accessed if you have the struct, which is pub(crate).

The principle I use is, if the type was public, what visibility would I want the method to have? In particular, if the method is necessary in order to use the type at all, then it should be pub.

Same as @kpreid for me. And I do this even within a module, e.g. a struct may be not-pub (implicitly pub(self)) but have pub methods.

The general idea is that changing the visibility of the struct[1] should mostly just work, and if it doesn't (i.e. a method also needs changed visibility), that means it's time to consciously think about how best to fill the gap.


  1. or e.g. moving it to a submodule and making it pub(super) ↩︎