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

2026-11-02来源 Rust Users ForumEnglish

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).

3 posts - 3 participants

Read full topic

原文:https://www.a8q9.cn/en/article/when-imlementing-non-private-methods-for-a-pub-crate-pub-super-struct-should-the-7baf5f.html

相关文章