pub const fn equals<L, R>(_lhs: &L, _rhs: &R) -> TypeCmp<L, R>Available on crate feature
rust_1_83 only.Expand description
Compared any two ConstMarkerEq types that have constants of the same type,
returning a proof of their type (in)equality.
ยงExample
use typewit::TypeCmp;
use typewit::const_marker::{self, ConstMarkerEq, Char, U8};
assert_eq!(typecast(Char::<' '>, Char::<' '>), Ok([Char::<' '>, Char::<' '>]));
assert_eq!(typecast(Char::<'X'>, Char::<'Y'>), Err((Char::<'X'>, Char::<'Y'>)));
assert_eq!(typecast(U8::<3>, U8::<3>), Ok([U8::<3>, U8::<3>]));
assert_eq!(typecast(U8::<5>, U8::<8>), Err((U8::<5>, U8::<8>)));
const fn typecast<L, R>(lhs: L, rhs: R) -> Result<[L; 2], (L, R)>
where
L: ConstMarkerEq,
R: ConstMarkerEq<Of = L::Of>,
{
match const_marker::equals(&lhs, &rhs) {
TypeCmp::Eq(te) => Ok([lhs, te.to_left(rhs)]),
TypeCmp::Ne(_) => Err((lhs, rhs))
}
}