SHARE
TWEET

Untitled

a guest Oct 14th, 2019 86 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.  
  9. fn distance_moved<T>(action: Action<T>) -> u32 {
  10.     if let Action::Moves(x) = action {
  11.         x
  12.     } else {
  13.         0
  14.     }
  15. }
  16.  
  17.  
  18. fn main(){
  19.     let mut player = Action::<String>::Moves(3);
  20.     println!("Player {:?}", player);
  21.     println!("Player moved = {:?}", distance_moved(player));
  22.     player = Action::Shoots("Enemy".to_string());
  23.     println!("Player {:?}", player);
  24.     println!("Player moved = {:?}", distance_moved(player));
  25.     player = Action::Waits;
  26.     println!("Player {:?}", player);
  27.     println!("Player moved = {:?}", distance_moved(player));
  28. }
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