Function comparing 2 variables of any type

If the types don't have any embedded references, you can use std::any::TypeId to do this:

fn eq<A:'static, B:'static>(_:A, _:B)->bool {
    std::any::TypeId::of::<A>() == std::any::TypeId::of::<B>()
}

For non-'static types, I think you'll need some kind of specialization, which is still an unstable feature.

3 Likes