23

Modules

Modules help developers better organize their source code. You can organize code hierarchically or based on context. The alternative to using modules is a monolithic approach where the entire application resides in a single source file. This approach becomes cumbersome when an application includes hundreds, even thousands, of lines of source code. Monolithic applications of that size are hard to navigate and maintain. You can reorganize your application into modules to prevent these sorts of problems.

Fundamentally, modules allow you to group related items. These include structs, enums, functions, and globals. However, modules can also be empty. The name of the module hopefully indicates its context. For example, a module named calculus ...

Get Programming with Rust now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.