好像没有其它语言的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 程序设计