Advertisement
Guest User

Untitled

a guest
Oct 14th, 2019
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.64 KB | None | 0 0
  1. #[derive(Debug)]
  2. enum Action<T> {
  3. Moves(u32),
  4. Shoots(T),
  5. Waits,
  6. }
  7.  
  8. fn is_attacking<T>(action: Action<T>) -> bool {
  9. match action {
  10. Action::Shoots(_) => true,
  11. _ => false,
  12. }
  13. }
  14.  
  15.  
  16. fn main(){
  17. let mut player = Action::<String>::Moves(3);
  18. println!("Player {:?}", player);
  19. println!("Player is attacking - {:?}", is_attacking(player));
  20. player = Action::Shoots("Enemy".to_string());
  21. println!("Player {:?}", player);
  22. println!("Player is attacking - {:?}", is_attacking(player));
  23. player = Action::Waits;
  24. println!("Player {:?}", player);
  25. println!("Player is attacking - {:?}", is_attacking(player));
  26. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement