Function unty::type_equal
source · pub fn type_equal<Src: ?Sized, Target: ?Sized>() -> bool
Expand description
Checks to see if the two types are equal.
assert!(type_equal::<u8, u8>());
assert!(!type_equal::<u8, u16>());
fn is_string<T>(_t: T) -> bool {
type_equal::<T, String>()
}
assert!(is_string(String::new()));
assert!(!is_string("")); // `&'static str`, not `String`
Note that this may give false positives if both of the types have lifetimes. Currently it is not possible to determine the difference between &'a str
and &'b str
.
assert!(type_equal::<&'a str, &'b str>()); // actual different types, this is not safe to transmute