Strange syntax woes

#1

Looking through warp’s documentation, I came upon this:

fn and(self, other: F) -> And<Self, F>
where
Self: Sized,
<Self::Extract as Tuple>::HList: Combine<<F::Extract as Tuple>::HList>,

What on earth is this line here and can someone point me at the rust documentation that covers this?
<Self::Extract as Tuple>::HList: Combine<<F::Extract as Tuple>::HList>,

Thank you in advance

#2

This is (most likely) a trait function where the trait has an associated type (named Extract), and that also requires the implementation of Tuple trait, which also has an associated type named HList, and the where clause is asking HList to have to implement Combine of generic type of (F's Extract (which implements Tuple) as a tuple)'s HList. Yeah, it’s pretty convoluted. There are a few places where the prices for this are explained, but looking for associated types is probably your best bet.
By the way, if you get stuck on those, think of them as generics, just slightly different.

#3

Breaking it down:

  • Self::Extract is referring to an associated type from Self.
  • <T as Tuple>::HList (for whatever T) refers to an associated type from T’s implementation of trait Tuple.
  • Given those two HList types, HList1: Combine<HList2> means the first must implement Combine with the other.
3 Likes