Rust中的模块及私有性控制

mac2022-06-30  19

好像没有其它语言的private, protected关键字,应了一个public关键字。

mod plant { pub struct Vegetable { pub name: String, _id: i32, } impl Vegetable { pub fn new(name: &str) -> Vegetable { Vegetable { name: String::from(name), _id: 1, } } } } fn main() { let mut v = plant::Vegetable::new("squash"); v.name = String::from("butternut squash"); println!("{} are delicious", v.name); }

  

转载于:https://www.cnblogs.com/aguncn/p/11405174.html

相关资源:rust 程序设计
最新回复(0)