[rust-dev] New privacy rules and crate-local scope

SiegeLord slabode at aim.com
Thu Oct 10 15:40:49 PDT 2013


On 10/10/2013 06:33 PM, Andrei de Araújo Formiga wrote:
> (hit send by mistake)
>
> Maybe I'm misunderstanding something, but you don't need to put
> everything inside the private module. There's even an example in the
> manual that does something like this:
>
> // this is the crate root
> mod internal
> {
>     pub fn internal_1() { }
> }
>
> pub mod external
> {
>     // public functions here will be available outside the crate
>
>     use internal; // pub functions in internal are now usable here
>
>     pub fn pub_api_1() { internal::internal_1() }
> }

The external API may need to access private implementation. Writing an 
internal API just so that the external API can access that 
implementation seems even more disruptive than sticking everything into 
a private module. E.g. in my example you'd have to write an accessor for 
the member m of struct S.

-SL



More information about the Rust-dev mailing list