Advertisement
Guest User

imp

a guest
Jan 19th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.30 KB | None | 0 0
  1. pub trait Job {
  2.     fn attack(&self) {
  3.         println!("ATTACKING")
  4.     }
  5. }
  6.  
  7. pub struct Warrior {}  
  8.  
  9. impl Warrior {
  10.     pub fn say_name(&self) {
  11.         println!("NAME")
  12.     }
  13. }
  14.  
  15. impl Job for Warrior {}
  16.  
  17. let player = Warrior{};
  18. player.say_name(); // => NAME
  19. player.attack(); // => ATTACK
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement