Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[allow(dead_code)]
- 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);
- // The next line won't compile if we uncomment it:
- // println!("The ID is {}", v.id);
- }
Add Comment
Please, Sign In to add comment