Items Visibility
pub is not implemented in the current release.By default, items are private to their module. Use pub to make them visible externally.
pub struct Config {
pub host: String;
pub port: uint16;
apiKey: String; // private field
}
pub func NewConfig(host: String, port: uint16) -> Config {
// Code here
}
Visibility applies independently to a type and to each of its fields. In Config above, the struct and its host/port fields are public, while apiKey stays private — code outside the module can construct and read a Config but cannot touch apiKey.
Only pub items can be reached through a qualified path or brought in with import.
See Also
- Module Declaration — the namespaces
pubexports from - Import — consuming exported items
Declaration
Modules organize code into named namespaces. A module is declared with the module keyword and can appear anywhere in a source file. Multiple modules can exist in one file, and modules can be nested.
Import
import brings names from a module into the current scope so they can be used without their full path. It comes in three forms: