Guest User

Untitled

a guest
Jan 21st, 2019
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.53 KB | None | 0 0
  1. #[allow(dead_code)]
  2.  
  3. mod plant {
  4. pub struct Vegetable {
  5. pub name: String,
  6. id: i32,
  7. }
  8.  
  9. impl Vegetable {
  10. pub fn new(name: &str) -> Vegetable {
  11. Vegetable {
  12. name: String::from(name),
  13. id: 1,
  14. }
  15. }
  16. }
  17. }
  18.  
  19. fn main() {
  20. let mut v = plant::Vegetable::new("squash");
  21.  
  22. v.name = String::from("butternut squash");
  23. println!("{} are delicious", v.name);
  24.  
  25. // The next line won't compile if we uncomment it:
  26. // println!("The ID is {}", v.id);
  27. }
Add Comment
Please, Sign In to add comment