/u/Gankro's "hacking generativity onto Rust" (section 6.3 here) and bluss's implementation. This is some of the most horrifying code I've ever seen, up there with Duff's device in C and partitioning lists in Python.
Basically, you can use lifetime-based black magic fuckery to move bound checks to compile-time.
Rust: you had my curiosity, but now you have my attention.
From this Reddit comment responding to "What is your favorite Rust code snippet?". It's full of links that I'm too lazy to copy over, but those links make it very informative (and funny).