11-结构体可见性

结构体可见性 — Rust 语言之旅

内容来源 · Tour of Rust / Rust 语言之旅

原文链接: https://tourofrust.com/116_zh-cn.html

结构体可见性

就像函数一样,结构体可以使用 pub 声明它们想要在模块外暴露的东西。

示例代码

1
2
3
4
5
6
7
8
9
// SeaCreature 结构体在我们的模块外面也能使用了
pub struct SeaCreature {
    pub animal_type: String,
    pub name: String,
    pub arms: i32,
    pub legs: i32,
    // 我们把武器信息保密起来好了
    weapon: String,
}
最后修改 August 21, 2026: 更新 (76fc81a2e)