Guest User

Untitled

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