Hi there, I just came across this situation:
fn my_fn<
'a,
I,
A: Really<Item=I> + ALot<'a, I> + ToType,
B: Really<Item=I> + ALot<'a, I> + ToType,
>(a: A, b: B)
{ ... }
And was wondering if I there is a syntax (or an RFC for it) to define trait bounds on multiple type parameters, something like:
fn my_fn<
'a,
I,
A & B: Really<Item=I> + ALot<'a, I> + ToType,
>(a: A, b: B)
{ ... }
The only way I would know to mitigate this is by implementing a utility trait:
trait ReallyALotToType<'a, I>: Really<Item=I> + ALot<'a, I> + ToType {}
impl<'a, I, T: Really<Item=I> + ALot<'a, I> + ToType> ReallyALotToType<'a, I> for T {}
fn my_fn<
'a,
I,
A: ReallyALotToType<'a, I>,
B: ReallyALotToType<'a, I>,
>(a: A, b: B)
{ ... }
But that doesn't scale as well as the first solution, especially when there are many type parameters involved in the trait. Also it introduces a lot of cognitive clutter, you have to think of a name for the trait, you have to implement it, all only really to tell the compiler something very simple: "These type parameters have the same trait bounds!"
The syntax could be debated, of course ,
would be the nicest to separate type parameter names before a trait bound, but that is already taken in this context. Other versions I could think of:
A : B: Trait,
A | B: Trait,
A B: Trait,
(A, B): Trait,
Maybe this could be taken even further and the type parameter context could allow for incremental definitions of trait bounds, i.e. type parameter names can be repeated to add new bounds, so that this would be possible:
<(A, B): Trait, A: Debug>