Implementing my own dynamic function dispatch in constant time

Hello,

I would like to implement something that resembles function overloading for functions that have multiple dynamically typed arguments. In other words, dynamic runtime dispatch that depends on the types of multiple function arguments.

I can make this work using safe Rust, like this (Rust Playground), but unfortunately the dispatch requires linear time with respect to the number of different supported types, because of Tracking Issue for `const fn` `type_id` · Issue #77125 · rust-lang/rust · GitHub

Has anybody found a better way to do this? Specifically to avoid the if…else if…else if…else execution and instead use something that’s constant time?

Thank you.