inflearn logo

Elegant Rust Intermediate (2) - Modules

As a Rust project grows, simply splitting the code into files makes it difficult to clearly manage responsibilities and visibility. In this course, we’ll cover everything step by step, from the differences between packages, crates, and modules to file organization, paths, visibility, separating libraries from executable files, re-exports, and workspaces.

6 learners are taking this course

Level Intermediate

Course period Unlimited

Rust
Rust
Rust
Rust

What you will gain after the course

  • You can distinguish between packages, crates, and modules and accurately read the structure of a Rust project.

  • You can connect multiple files to the module tree using `mod` declarations.

  • You can structure the project so that the roles of the library and executable are separated, making it easier to test.

  • You can design the boundaries between modules and crates based on their roles and reasons for change.

  • You can complete the library by connecting private modules and re-exporting only the necessary types and functions.

From Code Merely Split into Files to a Rust Project with Visible Boundaries

As a project grows, simply knowing which file contains the code is not enough. You also need to decide what responsibility each piece of code should take on, how much of it should be made public, and which code multiple executables should share.

In this course, you will start with the differences between packages, crates, and modules, which are often confused. Then, you will learn in order about module trees and file organization, the crate::, self::, and super:: paths, use, visibility, separating libraries and executables, re-exporting with pub use, and Cargo workspaces.

Finally, you will complete a library that hides the internal implementations of the model, parser, and report modules, allowing external users to access only the necessary types and functions through concise paths. The goal of this course is not merely to memorize syntax, but to design the boundaries of Rust projects so they are easy to modify and convenient to use.

You’ll learn the following:

Accurately distinguish between packages, crates, and modules

Learn the differences between packages managed by Cargo.toml, crates as compilation units, and modules that group code by role. Explore how src/lib.rs, src/main.rs, and src/bin each serve as the starting point for a different crate, and understand how to organize a library and multiple executable files within a single package. lần lượt là điểm bắt đầu của crate nào, đồng thời hiểu cách cấu trúc một thư viện và nhiều tệp thực thi trong cùng một package.

Even within a single package, the library and each executable are compiled as separate crates.

Understand how the module tree connects to file organization

Learn that a `mod` declaration is not syntax for simply copying a file, but a declaration that connects code to the module tree. Examine the differences between inline modules, parser.rs, and parser/mod.rs, and distinguish the logical structure of parent and child modules from the arrangement of the actual source files.


The module tree represents the logical relationships in the code, while files store the code for each module.

Complete the public API with a comprehensive exercise

Connect the already-implemented model, parser, and report code as private modules, and re-export only the types and functions needed externally from the crate root. Resolve the test failure messages one by one, hide the internal structure, and complete an easy-to-use library API yourself.

Notes Before Taking the Course

Practice environment

  • Operating systems and versions (OS): macOS, Linux, Windows

  • Tools: Git, VS Code, Rustup, Cargo

  • PC specifications: No particularly high-end PC required

Learning Materials

  • Online Study Materials

  • GitHub source code

Prerequisites and Notes

  • It is recommended that you take the introductory and practical course on Rust, an elegant, high-performance programming language.

  • This course is part of the Elegant Rust Intermediate Series.

Recommended for
these people

Who is this course right for?

  • Those who have completed an introductory Rust course but are still confused about the differences between packages, crates, and modules

  • For those wondering how to divide files and modules as a project grows

  • Those who frequently encounter path and visibility errors when using `mod`, `use`, and `pub`

  • Those who want to design easy-to-use library APIs that hide their internal implementations

Need to know before starting?

  • Basic knowledge of Rust syntax

  • Basic Concepts of Rust Ownership

Hello
This is hatemogi

Career Verified

2,120

Learners

169

Reviews

27

Answers

4.7

Rating

8

Courses

I am a backend developer with a strong interest in functional programming. I have led development teams as a development team manager at Kakao, a principal engineer at NHN, and a lead at LINE+. I also worked as the head of the development team at an AI startup called Dnotitia, where I worked on projects using Rust.

Curriculum

All

10 lectures ∙ (54min)

Published: 
Last updated: 

Reviews

Not enough reviews.
Please write a valuable review that helps everyone!

hatemogi's other courses

Check out other courses by the instructor!

Limited time deal

$7,150.00

35%

$8.80