第10章 模块

模块 — Rust By Example

译文 · 基于 Rust By Example

原文链接: https://doc.rust-lang.org/stable/rust-by-example/mod.html

模块

Rust 提供了一套强大的模块(module)系统,可以将代码按层次分成多个逻辑单元(模块),并管理这些模块之间的可见性(公有(public)或私有(private))。

模块是项(item)的集合,项可以是:函数,结构体,trait,impl 块,甚至其它模块。


01-可见性

可见性 — Rust By Example

02-结构体的可见性

结构体的可见性 — Rust By Example

03-`use` 声明

use 声明 — Rust By Example

04-`super` 和 `self`

super 和 self — Rust By Example

05-文件分层

文件分层 — Rust By Example

最后修改 August 21, 2026: 更新 (76fc81a2e)