Constify TypeId ordering impls by raldone01 · Pull Request #101698 · rust-lang/rust (original) (raw)

Some additional background that may help in the discussion:

I have created a crate called trait_cast_rs. It provides a custom Any type. That allows casts to dyn Traits.

Internally it has a const slice of function pointers with their associated TypeIds. Making TypeId const comparable would allow the crate to sort the slice at compile time. When downcasting at runtime a binary_search is performed to find the correct function pointer.

This has the advantage that the array must not be sorted on every program launch and the lookup slice can be a constant.

I currently use transmute<_, u64>(type_id) to sort the slice at compile time.