xtask: Fix deprecation warnings with rand 0.9#1766
Conversation
The rand crate was bumped from 0.8 -> 0.9 in 7804be9 Signed-off-by: John Eckersberg <jeckersb@redhat.com>
There was a problem hiding this comment.
Code Review
This pull request updates the rand crate from version 0.8 to 0.9 and fixes the resulting deprecation warnings in xtask. The changes are correct and achieve the goal of the PR. I've added one suggestion to make the random string generation more idiomatic using features from the rand crate.
| let mut rng = rand::rng(); | ||
| const CHARSET: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789"; | ||
| (0..8) | ||
| .map(|_| { | ||
| let idx = rng.gen_range(0..CHARSET.len()); | ||
| let idx = rng.random_range(0..CHARSET.len()); | ||
| CHARSET[idx] as char | ||
| }) | ||
| .collect() |
There was a problem hiding this comment.
While this is a correct fix for the deprecation warning, this implementation can be made more idiomatic and concise by using SliceRandom::choose to pick a random character directly from the CHARSET.
Here's how you could refactor the function body:
const CHARSET: &[u8] = b"abcdefghijklmnopqrstuvwxyz0123456789";
(0..8)
.map(|_| *CHARSET.choose(&mut rand::rng()).unwrap() as char)
.collect()This would require adding use rand::seq::SliceRandom; at the top of the file. Since this change is outside the diff, I'm providing this as a suggestion for you to consider.
The rand crate was bumped from 0.8 -> 0.9 in 7804be9
Signed-off-by: John Eckersberg jeckersb@redhat.com