Guest User

Untitled

a guest
Mar 22nd, 2018
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.76 KB | None | 0 0
  1. #![allow(unused)]
  2.  
  3. trait TypeFunction {
  4. type Out;
  5. }
  6.  
  7. struct S1;
  8.  
  9. //LIKE SO
  10. impl TypeFunction for S1 where
  11. TypeFunction::Out = i16
  12. {
  13. type Out = i16;
  14. }
  15.  
  16. impl TypeFunction for S1 where
  17. TypeFunction::Out = i32
  18. {
  19. type Out = i32;
  20. }
  21.  
  22. impl TypeFunction for S1 where
  23. TypeFunction::Out = i64
  24. {
  25. type Out = i64;
  26. }
  27.  
  28. // You can consider TypeFunction trait to be a function on types, that maps
  29. // a TYPE (e.g. S1/S2/S3) to some other TYPE (i16/i32/i64).
  30.  
  31. // This is fundamentally a result of the fact that you can implement the trait
  32. // only once for every type. And so for every type there's at most one single Out type.
  33.  
  34. // So there's no way to replicate this with something like "trait OtherFunction<Out> {}"
  35. // because a generic parameter varies across all types.
  36.  
  37. fn main() {}
Add Comment
Please, Sign In to add comment