How to split code using private parts into a seperate file?


I prefer small source code files. Files are modules and therefore splitting a file changes method visibility.

Is it at all possible to have one file:

# file A
struct A{ x : u32}

and another

f(a: A) {

where of course both are exported from some other module, so that the abstraction doesn't leak. Essentially it's possible to have both A and f in single module (put into single file), but can I split those into two modules and export from 2 namespaces?

One thing is can I split that into 2 source files.
Second question is can I define A and f wherever, but export them from two different namespaces?

Every child module has access to all private items of its ancestors.

Can you make the module in which f is a child of the module in which A is? Re-export f in A's module. This way you can have separate files.


Another thing you can do is pub(<somepath>). For example, you can put pub(super) to only make it public to the parent module and its descendants.


oh wow, didn't know this feature