Advertisement
Guest User

Untitled

a guest
Aug 18th, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.41 KB | None | 0 0
  1. trait Moo {
  2. fn moo(&self) -> String;
  3. }
  4.  
  5. trait SuperMoo: Moo {
  6. fn supermoo(&self) {
  7. println!("Super! {}", self.moo());
  8. }
  9.  
  10. fn supercow() {
  11. println!("SuperCow!");
  12. }
  13. }
  14.  
  15. struct Cow {
  16.  
  17. }
  18.  
  19. impl Moo for Cow {
  20. fn moo(&self) -> String {
  21. "MOOOOO".to_string()
  22. }
  23. }
  24.  
  25. fn main() {
  26. let c = Cow{};
  27. let m = Box::new(c) as Box<Moo>;
  28. <c as SuperMoo>::supercow();
  29. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement