pub trait Same<Rhs = Self> {
type Output;
}
Expand description
A type operator that ensures that Rhs
is the same as Self
, it is mainly useful
for writing macros that can take arbitrary binary or unary operators.
Same
is implemented generically for all types; it should never need to be implemented
for anything else.
Note that Rust lazily evaluates types, so this will only fail for two different types if
the Output
is used.
Example
use typenum::{Same, Unsigned, U4, U5};
assert_eq!(<U5 as Same<U5>>::Output::to_u32(), 5);
// Only an error if we use it:
type Undefined = <U5 as Same<U4>>::Output;
// Compiler error:
// Undefined::to_u32();