mirror of
https://github.com/rust-lang/book.git
synced 2026-11-30 19:04:31 -06:00
@@ -5,11 +5,14 @@ the `main` function. As your code grows, you eventually move functionality out
|
||||
into functions, both for re-use and for nicer organization. By splitting your
|
||||
code up into smaller chunks, each chunk is easier to understand on its own. So
|
||||
what happens when you start having too many functions? Rust has a module system
|
||||
that tackles both of these problems. In the same way that you extract some lines
|
||||
of code into a function, you can extract some functions (and other things too)
|
||||
into different modules. A *module* is a namespace that contains definitions of
|
||||
functions or types, and those definitions can be visible outside their module
|
||||
or not. Here's an overview of how the bits fit together:
|
||||
that tackles both the problem of wanting to be able to re-use code and the
|
||||
problem of keeping your code organized.
|
||||
|
||||
In the same way that you extract lines of code into a function, you can extract
|
||||
functions (and other code like structs and enums too) into different modules. A
|
||||
*module* is a namespace that contains definitions of functions or types, and
|
||||
those definitions can be visible outside their module or not. Here's an
|
||||
overview of how the bits fit together:
|
||||
|
||||
* `mod` declares a new module.
|
||||
* Everything starts off as private, but the `pub` keyword makes it public.
|
||||
|
||||
Reference in New Issue
Block a user