Hey all, I’m trying to create a generic type list like so:
trait List {
type Head;
type Tail;
}
impl<H> List for (H, ()) {
type Head = H;
type Tail = ();
}
impl<H, T: List> List for (H, T) {
type Head = H;
type Tail = (<Self::Tail as List>::Head, <Self::Tail as List>::Tail);
}
So effectively each tail type would recursively get the next tail type as a List until I hit a List that has a unit type tail type. Unfortunately, the compiler errors out with an inability to parse the infinitely recursive type. I know that boxing the recursive type is what would normally be suggested here, but heap allocations are strictly not allowed for my particular use case. Any suggestions on how to encode this kind of recursive type into the type system without the compiler freaking out?