Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
93
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. struct Kiwi;
  2.  
  3. impl Kiwi {
  4. fn greet(&mut self) {
  5. println!("Hello Fellas!");
  6. }
  7.  
  8. fn eat(&self) {
  9. println!("I feel it in my code.");
  10. }
  11. }
  12.  
  13. trait Fruit {
  14. fn greet(&self) {
  15. println!("I love fruits!");
  16. }
  17.  
  18. fn eat(&self) {
  19. println!("I feel it in my pulp.");
  20. }
  21. }
  22.  
  23. impl Fruit for Kiwi {}
  24.  
  25. fn main() {
  26. let mut kiwi = Kiwi;
  27. kiwi.greet();
  28. (&mut kiwi).greet();
  29. kiwi.eat();
  30. (&kiwi as &Fruit).eat();
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement