For example, if I implement for f32 which will return Enum::A and implement for i32 which will return Enum::C(1), then we get Enum<f32,_> and Enum<_,i32>.
The problem is when I want to those enums into a vec: it fails because _ doesn't implement Copy.
So, is the only way to implement a Dummy or Empty type for all traits to replace _ ?
Copy is a red herring: you cannot ever have a value of an actual type with missing elements like Enum<f32, _>. Both type parameters must be known.
In a lot of cases, this is not a problem because as long as you have values of both types flowing into the same place (e.g. a Vec<Enum<_, _>> that has Enum<f32, _> and Enum<i32, _> elements inserted will get resolved to Vec<Enum<f32, i32>>. But in any place where you only use A and not C, or C and not A, you will have to specify some placeholder for the other type. () is usually a reasonable choice, but the theoretically optimal one is an empty enum β enum Nothing {} β which has no values at all.
Ok I was hoping rust could handle this by providing a feature like Phantom type.
So for now, I will create it on my own and implement it for all my traits !!
Thank you for your support.
Ok I was hoping rust could handle this by providing a feature like Phantom type.
There is a work-in-progress feature, the βneverβ type, which will be most suitable for this sort of use case once it is stable (or if you're using nightly Rust you can use it now). There's also one empty enum in the standard library, std::convert::Infallible, but it's intended for use as an error type in particular.
I tried both, but it gives me the same result: I must implement all my traits for both case... So, finally, it is exactly the same as creating a Phantom type by myself.
I know this is an unusual case and only few people should solve such a problem by creating a Dummy type.
Maybe rust will allow _ to bypass any trait for example in the future.