我需要测试两种类型是否相等在const fn
里。比较TypeId
是行不通的:
#![feature(const_if_match)]
#![feature(const_fn)]
#![feature(const_type_id)]
const fn t<T1: 'static, T2: 'static>() -> bool{
std::any::TypeId::of::<T1>() == std::any::TypeId::of::<T2>()
}
错误:
error[E0015]: calls in constant functions are limited to constant functions, tuple structs and tuple variants
--> src/lib.rs:5:8
|
5 | std::any::TypeId::of::<T1>()==std::any::TypeId::of::<T2>()
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
在 Rust 中,像 C++ 中的模板特化并不起作用,因为 Rust 没有 "模板特化"。那么,在 Rust 中有没有任何方法可以测试类型相等性呢?
'static
。 - undefined