Shouldn't struct fields be private in all cases?


#1

This seems to work fine: http://is.gd/YBAiAW
Shouldn’t printing the contents of blackbox fail? The only difference between this and the example here http://rustbyexample.com/mod/struct_visibility.html is that I removed the mod declaration at the top. Where am I going wrong?


#2

Privacy doesn’t apply within a module; private things are only private to code outside the defining module. In this case, everything is in the same module, so nothing is really private.

To quote the third sentence from the page you linked:

This visibility only matters when a struct is accessed from outside the module where it is defined…


#3

Makes sense, thanks!