Open
Description
Is there any way to compare 2 TypeId
s in const
context? (It's possible to create them in const
context, and it's even soon to be stabilized)
What I want is a static check for type (un)equality without auto trait
s:
// will fail with index out of bounds if T == U
const _: () = [()][(TypeId::of::<T>() == TypeId::of::<U>()) as usize];
(this exact code currently fails to compile with "calls in constants are limited to constant functions, tuple structs and tuple variants" error, because ==
isn't const
)
Maybe it's a good idea to add API like the following to TypeId?
impl TypeId {
const fn eq(&self, rhs: &Self) -> bool {
self.t == rhs.t
}
}
I could work on this, though I haven't seen similar apps in std, so I wanted to ask about it before doing anything.