Guest User

Untitled

a guest
Apr 23rd, 2018
104
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. trait IA {
  2. fn f(&self);
  3. fn g(&self) {
  4. println!("IA::g")
  5. }
  6. }
  7.  
  8. trait IB {
  9. fn f(&self);
  10. fn g(&self) {
  11. println!("IB::g")
  12. }
  13. }
  14.  
  15. trait IC : IA {
  16. fn h(&self);
  17. }
  18.  
  19. struct Q(i32);
  20.  
  21. impl IA for Q {
  22. fn f(&self) {
  23. println!("Q::IA::f | {}", self.0)
  24. }
  25. }
  26.  
  27. impl IB for Q {
  28. fn f(&self) {
  29. println!("Q::IB::f | {}", self.0)
  30. }
  31. }
  32.  
  33. impl IC for Q {
  34. fn h(&self) {
  35. println!("Q::IC::h | {}", self.0)
  36. }
  37. }
  38.  
  39. fn test_ia(ia: &IA) {
  40. ia.f();
  41. ia.f();
  42. ia.f();
  43. }
  44.  
  45. fn test_ic_ia(ia: &IC) {
  46. ia.f();
  47. ia.f();
  48. ia.f();
  49. }
  50.  
  51. fn test_ic(ic: &IC) {
  52. ic.h();
  53. test_ic_ia(ic);
  54. }
  55.  
  56. fn main() {
  57. let q = Q(7);
  58. test_ia(&q);
  59. println!();
  60. test_ic(&q);
  61. println!();
  62. println!("{}", std::mem::size_of::<Q>());
  63. println!("{}", std::mem::size_of::<&IA>());
  64. println!("{}", std::mem::size_of::<&IB>());
  65. println!("{}", std::mem::size_of::<&IC>());
  66. }
Add Comment
Please, Sign In to add comment