//@ build-pass #![allow(incomplete_features)] #![feature(generic_const_exprs)] trait Collate { type Pass; type Fail; fn collate(self) -> (Self::Pass, Self::Fail); } impl Collate for () { type Pass = (); type Fail = (); fn collate(self) -> ((), ()) { ((), ()) } } trait CollateStep { type Pass; type Fail; fn collate_step(x: X, prev: Prev) -> (Self::Pass, Self::Fail); } impl CollateStep for () { type Pass = (X, P); type Fail = F; fn collate_step(x: X, (p, f): (P, F)) -> ((X, P), F) { ((x, p), f) } } struct CollateOpImpl; trait CollateOpStep { type NextOp; type Apply; } impl CollateOpStep for CollateOpImpl where CollateOpImpl<{ MASK >> 1 }>: Sized, { type NextOp = CollateOpImpl<{ MASK >> 1 }>; type Apply = (); } impl Collate for (H, T) where T: Collate, Op::Apply: CollateStep, { type Pass = >::Pass; type Fail = >::Fail; fn collate(self) -> (Self::Pass, Self::Fail) { >::collate_step(self.0, self.1.collate()) } } fn collate(x: X) -> (X::Pass, X::Fail) where X: Collate>, { x.collate() } fn main() { dbg!(collate::<_, 5>(("Hello", (42, ('!', ()))))); }