SHARE
TWEET

Untitled

a guest Oct 14th, 2019 83 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top