pub fn static_type_eq<T1, T2>() -> boolExpand description
Returns true if the T1 and T2 static types are equal.
This method requires both T1 and T2 to be 'static.
Library tests ensure that type comparisons are performed at compile time and
are fully optimized with no runtime cost at opt-level >= 1. Note that the
release profile uses opt-level = 3 by default.
ยงExamples
use try_specialize::static_type_eq;
fn static_type_eq_of_vals<T1: 'static, T2: 'static>(_: T1, _: T2) -> bool {
static_type_eq::<T1, T2>()
}
assert!(static_type_eq::<(), ()>());
assert!(!static_type_eq::<(), u8>());
assert!(static_type_eq::<u8, u8>());
assert!(!static_type_eq::<u8, u32>());
assert!(static_type_eq::<[u8], [u8]>());
assert!(static_type_eq::<[u8; 8], [u8; 8]>());
assert!(!static_type_eq::<[u8; 8], [u8]>());
assert!(!static_type_eq::<[u8], [u8; 8]>());
assert!(!static_type_eq::<[u8; 8], [u8; 16]>());
assert!(static_type_eq::<&'static str, &'static str>());
assert!(static_type_eq_of_vals("foo", "bar"));
assert!(static_type_eq::<str, str>());
assert!(static_type_eq::<[u8], [u8]>());
assert!(!static_type_eq::<str, [u8]>());
assert!(!static_type_eq::<[u8], [u8; 4]>());
assert!(static_type_eq::<String, String>());