Guest User

Untitled

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