Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #[derive(Debug)]
- enum Action<T> {
- Moves(u32),
- Shoots(T),
- Waits,
- }
- fn is_attacking<T>(action: Action<T>) -> bool {
- match action {
- Action::Shoots(_) => true,
- _ => false,
- }
- }
- fn main(){
- let mut player = Action::<String>::Moves(3);
- println!("Player {:?}", player);
- println!("Player is attacking - {:?}", is_attacking(player));
- player = Action::Shoots("Enemy".to_string());
- println!("Player {:?}", player);
- println!("Player is attacking - {:?}", is_attacking(player));
- player = Action::Waits;
- println!("Player {:?}", player);
- println!("Player is attacking - {:?}", is_attacking(player));
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement