daily pastebin goal
62%
SHARE
TWEET

Untitled

a guest Feb 22nd, 2019 65 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #[derive(Debug)]
  2. pub struct Deck<'a> {
  3.    cards: Vec<&'a str>,
  4. }
  5.  
  6. impl<'a> Deck<'a> {
  7.     pub fn new(cards: Vec<&'a str>) -> Self {
  8.         Deck { cards }
  9.     }
  10.     pub fn pop(&mut self) -> &str {
  11.         self.cards.pop().unwrap()
  12.     }
  13. }
  14.  
  15. #[derive(Debug)]
  16. pub struct Player<'a> {
  17.     deck: &'a mut Deck<'a>,
  18. }
  19.  
  20. impl<'a> Player<'a> {
  21.     pub fn new(deck: &'a mut Deck<'a>) -> Self {
  22.         Player { deck }
  23.     }
  24.    
  25.     pub fn draw(&mut self) {
  26.         self.deck.pop();
  27.     }
  28. }
  29.  
  30. fn main() {
  31.     let mut deck = Deck::new(vec![]);
  32.    
  33.     let mut player = Player::new(&mut deck);
  34.    
  35.     player.draw();
  36.    
  37.     println!("{:?}", player);
  38. }
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