Advertisement
Guest User

Untitled

a guest
Jul 17th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. // A trait to implement all the shared functions that can be overriden
  2. trait BaseTrait {
  3. fn foo0(&self) { println!("Foo 0!") }
  4. fn foo1(&self) { println!("Foo 1!") }
  5. }
  6.  
  7. // An 'inheriting class' that implements some functions of it's own and overrides on
  8. // Composited one
  9. struct SubClass{}
  10. impl SubClass {
  11. fn foo2(&self) { println!("Foo 2!") }
  12. fn foo1(&self) { println!("Foo 1 from 'Subclass'")}
  13. }
  14. impl BaseTrait for SubClass {}
  15.  
  16. // A base 'class' that doesn't require any implementation
  17. struct BaseClass{}
  18. impl BaseTrait for BaseClass{}
  19.  
  20. fn main() {
  21.  
  22. let s = SubClass{};
  23. s.foo0();
  24. s.foo1();
  25. s.foo2();
  26.  
  27. let base = BaseClass{};
  28. base.foo0();
  29. base.foo1();
  30.  
  31. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement