Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. struct Texture {
  2. image: String,
  3. }
  4.  
  5. impl Texture {
  6. fn new(texture: String) -> Texture {
  7. Texture {
  8. image: texture,
  9. }
  10. }
  11.  
  12. fn image(&self) -> &String {
  13. &self.image
  14. }
  15. }
  16.  
  17. trait Character {
  18. fn name(&self) -> &String;
  19. fn texture(&self) -> &Texture;
  20. }
  21.  
  22. struct Player {
  23. name: String,
  24. texture: Texture,
  25. }
  26.  
  27. impl Player {
  28. fn new() -> Player {
  29. Player {
  30. name: String::from("Goku"),
  31. texture: Texture::new(String::from("image.png")),
  32. }
  33. }
  34. }
  35.  
  36. impl Character for Player {
  37. fn name(&self) -> &String {
  38. &self.name
  39. }
  40.  
  41. fn texture(&self) -> &Texture {
  42. &self.texture
  43. }
  44. }
  45.  
  46. fn main() {
  47. let player: Player = Player::new();
  48.  
  49. println!("Player name: {}", player.name());
  50. println!("Player image: {}", player.texture().image())
  51. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement