Advanced Hands-on Rust: Rust 2024, gen, and the rand crate

This is probably going to come up if it hasn’t already, but if you try to use Rust 2024 edition with the Advanced Hands-on Rust code, you’re going to have issues with the rand crate. In Rust 2024, gen is now a reserved keyword, and the rand crate addresses this in version 0.9+ by replacing gen with random in its main API calls: gen()random(), gen_range()random_range(), etc.

Here’s the RFC for the Rust 2024 change: 3513-gen-blocks - The Rust RFC Book

Here’s the rand crate info on the subject: Updating to 0.9 - The Rust Rand Book

I would suggest you stick with the Rust 2021 and other crate versions as specified in the code examples so you aren’t battling this sort of issue in addition to trying to learn the topics of the book.

Hope this helps anyone who comes here first looking for a reason why things aren’t working!