liveBook · Manning

Module

As explained in Rust Servers, Services, and Apps

The Rust module system organizes code into named modules that provide separation and visibility boundaries.

Rust modules organize application code into named areas, separating functionality such as HTTP handlers, database access, models, and application state. This structure supports clear responsibility boundaries as a web application grows. section 1.3.2 section 6.4

pub mod auth;    #1
pub mod course;  #2

A handler module can expose authentication and course functionality as separate public submodules. section 9.4

In the web application, module organization develops alongside its features:

  • An initial application groups database access, errors, handlers, models, routes, and state under a module configured with `mod.rs`. section 8.1
  • As course maintenance is added, handler files are split into authentication and course modules; routes import their handlers, and the application configures the routes. section 9.4

How Rust Servers, Services, and Apps covers it

How deep it goes
Shows file restructuring, module declarations, imports, and exports through application code.
Examples
Uses an initial application module and later splits handlers into authentication and course modules.
What you can do after
Build application modules that separate authentication and course handlers, then import and configure their routes.
How it connects
Connects module organization with Cargo workspaces, the single responsibility principle, HTTP handlers, and database access.

Also explained in

Compare how 35 books explain module →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Rust Servers, Services, and Apps. The section links point to the parts of the book it draws on.