Trait type_equalities::IsEqual [−][src]
Equality at a constraint level, as a type alias. Reflexivity holds.
Example
Note that due to the rust type checker, coercions are not as simple as they might look.
ⓘ
// Trying to implement coerce like this fails! fn foo<U, T: IsEqual<U>>(t: T) -> U { t } assert_eq!(foo::<u32, u32>(42), 42) // | // 6 | fn foo<U, T: IsEqual<U>>(t: T) -> U { t } // | - - - ^ expected type parameter `U`, found type parameter `T` // | | | | // | | found type parameter expected `U` because of return type // | expected type parameter
But the following works correctly:
fn foo<U, T: IsEqual<U>>(t: T) -> U { trivial_eq().coerce(t) } assert_eq!(foo::<u32, u32>(42), 42)