Need a unique gift idea?
A Pastebin account makes a great Christmas gift
SHARE
TWEET

Untitled

a guest Jul 21st, 2018 67 Never
Upgrade to PRO!
ENDING IN00days00hours00mins00secs
 
  1. trait X {
  2.     fn x(&self) -> i32;
  3. }
  4. trait Y {
  5.     fn y(&self) -> i32;
  6. }
  7.  
  8. // question: i have implemented X for Y, so
  9. // shouldn't this mean all instances of Y are
  10. // also X?
  11. impl X for Y {
  12.     fn x(&self) -> i32 {
  13.         123
  14.     }
  15. }
  16.  
  17. // question: here i have a struct Z, and I
  18. // implement Y for Z, and Y implements X, so
  19. // shouldn't X by implemented for Z by way of
  20. // Y?
  21. struct Z;
  22. impl Y for Z {
  23.     fn y(&self) -> i32 {
  24.         0
  25.     }
  26. }
  27.  
  28. fn test(y: Box<dyn Y>) {
  29.     println!("{}", y.x());
  30. }
  31.  
  32. fn main() {
  33.     let z = Box::new(Z);
  34.     test(z);
  35.    
  36. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top