Solving Advent of Code at compile time with Rust macros
doublefree.bearblog.dev
doublefree.bearblog.dev
The article then proceeds to produce barely legible code, but it's in Rust instead! I would leave out own-goals like this, it detracts from the content.
```py """Warning: This code completes in a shocking O(n log n) time complexity and allocates memory with reckless abandon""" ```
How shocking that sorting is an O(n log n) algorithm.
Edit: he then goes on to use bubble sort.
I think there might be a large amount of tounge in cheek with this blog post, but it doesn't really land.
The answer is produced as a compiler error and so there is zero runtime at all.
The whole post is written to be a little ridiculous, but I must not have gotten that across =(
I agree with you. In real life, python is absolutely a better choice than trying to write a Rust macro to produce the result as a compiler error.
I added a footnote to the end of the referenced paragraph to say that python is great.
[1] https://doc.rust-lang.org/book/ch19-06-macros.html
[2] https://doc.rust-lang.org/book/ch19-06-macros.html#procedura...
I found "The Little Book of Rust Macros"[1] to be a really good resource for getting started with Rust's declarative macros.