fn main() { println!("{}", (1, (2, (4, Empty()))).get(2)); } struct Empty (); trait Cons { type Tail: Cons; fn get_head(&self) -> &T; fn get_tail(&self) -> &Self::Tail; fn get(&self, index: usize) -> &T { match index { 0 => self.get_head(), x => self.get_tail().get(x - 1) } } } impl> Cons for (T, C) { type Tail = C; fn get_head(&self) -> &T { &self.0 } fn get_tail(&self) -> &Self::Tail { &self.1 } } impl Cons for Empty { type Tail = Empty; fn get_head(&self) -> &T { panic!() } fn get_tail(&self) -> &Self::Tail { panic!() } }