Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // A trait to implement all the shared functions that can be overriden
- trait BaseTrait {
- fn foo0(&self) { println!("Foo 0!") }
- fn foo1(&self) { println!("Foo 1!") }
- }
- // An 'inheriting class' that implements some functions of it's own and overrides on
- // Composited one
- struct SubClass{}
- impl SubClass {
- fn foo2(&self) { println!("Foo 2!") }
- fn foo1(&self) { println!("Foo 1 from 'Subclass'")}
- }
- impl BaseTrait for SubClass {}
- // A base 'class' that doesn't require any implementation
- struct BaseClass{}
- impl BaseTrait for BaseClass{}
- fn main() {
- let s = SubClass{};
- s.foo0();
- s.foo1();
- s.foo2();
- let base = BaseClass{};
- base.foo0();
- base.foo1();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement