In Rust, is there any way to, at the type level, summon an Add
implementation by using the LHS (Self
) and RHS types in order to use its Output
type (in say, the return type of a generic function)?
There is, although it does look like a bit of black magic.
You need to combine 3 bits of syntax:
<Type as Trait>
RHS
simply requires passing it as a parameter Add<???>
Trait::OutputType
(which may be ambiguous)Combining the 3 together we get <Self as Add<RhsType>>::Output
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With