Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #![allow(unused)]
- trait TypeFunction {
- type Out;
- }
- struct S1;
- //LIKE SO
- impl TypeFunction for S1 where
- TypeFunction::Out = i16
- {
- type Out = i16;
- }
- impl TypeFunction for S1 where
- TypeFunction::Out = i32
- {
- type Out = i32;
- }
- impl TypeFunction for S1 where
- TypeFunction::Out = i16
- {
- type Out = i64;
- }
- // You can consider TypeFunction trait to be a function on types, that maps
- // a TYPE (e.g. S1/S2/S3) to some other TYPE (i16/i32/i64).
- // This is fundamentally a result of the fact that you can implement the trait
- // only once for every type. And so for every type there's at most one single Out type.
- // So there's no way to replicate this with something like "trait OtherFunction<Out> {}"
- // because a generic parameter varies across all types.
- fn main() {}
Add Comment
Please, Sign In to add comment