Advertisement
Guest User

Untitled

a guest
Apr 22nd, 2019
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.77 KB | None | 0 0
  1. struct WeaponData {
  2. damage: usize,
  3. }
  4.  
  5. struct ArmorData {
  6. protection: usize,
  7. }
  8.  
  9. struct ConsumeableData {
  10. healing: usize,
  11. }
  12.  
  13. impl WeaponData {
  14. fn do_damage(&self) {}
  15. }
  16.  
  17. impl ArmorData {
  18. fn mitigate_damage(&self) {}
  19. }
  20.  
  21. enum Item {
  22. Weapon(WeaponData),
  23. Armor(ArmorData),
  24. Consumeable(ConsumeableData),
  25. }
  26.  
  27. use Item::*;
  28.  
  29. pub fn main() -> () {
  30. let sword = Weapon(WeaponData { damage: 6 });
  31. let armor = Armor(ArmorData { protection: 6 });
  32. let poition = Consumeable(ConsumeableData{ healing: 6 });
  33.  
  34. let equipment = vec![sword, armor, poition];
  35.  
  36. for e in equipment {
  37. match e {
  38. Weapon(weapon) => { weapon.do_damage(); }
  39. Armor(armor) => { armor.mitigate_damage(); }
  40. _ => { }
  41. }
  42. }
  43. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement