Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- trait IA {
- fn f(&self);
- fn g(&self) {
- println!("IA::g")
- }
- }
- trait IB {
- fn f(&self);
- fn g(&self) {
- println!("IB::g")
- }
- }
- trait IC : IA {
- fn h(&self);
- }
- struct Q(i32);
- impl IA for Q {
- fn f(&self) {
- println!("Q::IA::f | {}", self.0)
- }
- }
- impl IB for Q {
- fn f(&self) {
- println!("Q::IB::f | {}", self.0)
- }
- }
- impl IC for Q {
- fn h(&self) {
- println!("Q::IC::h | {}", self.0)
- }
- }
- fn test_ia(ia: &IA) {
- ia.f();
- ia.f();
- ia.f();
- }
- fn test_ic_ia(ia: &IC) {
- ia.f();
- ia.f();
- ia.f();
- }
- fn test_ic(ic: &IC) {
- ic.h();
- test_ic_ia(ic);
- }
- fn main() {
- let q = Q(7);
- test_ia(&q);
- println!();
- test_ic(&q);
- println!();
- println!("{}", std::mem::size_of::<Q>());
- println!("{}", std::mem::size_of::<&IA>());
- println!("{}", std::mem::size_of::<&IB>());
- println!("{}", std::mem::size_of::<&IC>());
- }
Add Comment
Please, Sign In to add comment