Live streamed another episode of Advent Of Code in Rust on Twitch:
Advent of code in Rust - solving day 2/2021 (Twitch Live 2022-01-17)
https://youtu.be/F6GvFX4voAQ
In this episode, we completed day 2 of Advent of Code y2021 using Rust!
This exercise required us to do a little bit of parsing to process a sequence of instructions that would make a submarine move.
The solution was simple enough but we wanted to get a bit fancy and experiment a little bit.
Our initial solution used the `FromIterator` trait which allows you to call `collect()` on an iterator to produce a custom type: https://doc.rust-lang.org/stable/std/iter/trait.FromIterator.html
We essentially used this as a replacement for something like `fold` which would have probably been a bit more idiomatic: https://doc.rust-lang.org/std/iter/trait.Iterator.html#method.fold
But hey, sometimes you just want to have fun and try something new :)
The first and the second part of the exercise had a few repeated bits that we thought could use some refactoring.
We ended up experimenting with custom traits and blanket implementations, only to find out that you cannot really provide a blanket implementation for another trait without having a wrapper struct.
This was an interesting learning, but in the end, we didn't think it made our solution simpler so we ended up ditching those changes.
If you have any suggestion, we'd love to hear it, so please leave a comment or a create a PR!
For all the source code check out the official GitHub repo: https://github.com/lmammino/rust-advent
For seeing the next episodes live check out our Twitch channel: https://twitch.tv/loige