Given some generic type T, I want to inspect in some way if T has Trait and if so, perform checks on <T as Trait>::SomeAssociatedType, i.e. check the size with std::mem::size_of::<_>().
I've done some looking around and while I've found good content on downcasting, none of them seem to fit my need. Most notable, most of them involve trait objects, which I don't necessarily need here.
This playground is a minimum example of what I want to do, see the check_stuff function and the rest should be clear.
Also, note that in this example I am passing an instance of Struct to the function as well, but in reality that should not be needed. All of the inspections that I want to do are on the associated types of <Struct as SomeTrait>, so no need for the instance.
This RFC proposes a design for specialization , which permits multiple impl blocks to apply to the same type/trait, so long as one of the blocks is clearly "more specific" than the other. The more specific impl block is used in a case of overlap...
Indeed related, but not quite just. I do not care about the question of which impl to use. I care for just checking if it is implemented or not, without adding more trait bounds.
You can’t define this correctly over all types without specialization, but it can still help if you’re dealing with only a well-defined subset of all types.