pub trait TypeIsEqual {
type To: ?Sized;
}
Expand description
Helper trait for type equality, necessary to make IntoExt::into_
work.
Generically implemented so that T: TypeIsEqual<To = T>
holds for all types.
§Example
If you have an S: TypeIsEqual<To = T>
bound, this trait can be used by using a generic
function with arguments or return values of type S
and <S as TypeIsEqual>::To
.
fn convert_one_way<S, T>(s: S) -> T
where
S: TypeIsEqual<To = T>,
{
fn helper<S>(s: S) -> <S as TypeIsEqual>::To {
s
}
helper(s)
}
fn convert_other_way<S, T>(t: T) -> S
where
S: TypeIsEqual<To = T>,
{
fn helper<S>(t: <S as TypeIsEqual>::To) -> S {
t
}
helper(t)
}
The same works if the corresponding types are part of a larger type, e.g. you can convert
&mut [Option<S>]
to &mut [Option<T>]
and things like that.