1分钟内可阅读完
内容来源 · Tour of Rust / Rust 语言之旅
原文链接: https://tourofrust.com/116_zh-cn.html
就像函数一样,结构体可以使用 pub 声明它们想要在模块外暴露的东西。
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, }