rand-0-8-to-0-9
Automate the deterministic Rust rand migration from v0.8 to v0.9 for the most common API renames.
What it does
RNG constructor updates
- rand::thread_rng() -> rand::rng()
- thread_rng() -> rng() when imported from rand
- use rand::thread_rng; -> use rand::rng;
- use rand::{..., thread_rng, ...}; -> use rand::{..., rng, ...};
- Supports aliased imports (thread_rng as foo -> rng as foo)
Method renames
- .gen(...) -> .random(...)
- .gen_range(...) -> .random_range(...)
- .gen_bool(...) -> .random_bool(...)
- .gen_ratio(...) -> .random_ratio(...)
- Rng::gen(...) -> Rng::random(...)
- Rng::gen_range(...) -> Rng::random_range(...)
- Rng::gen_bool(...) -> Rng::random_bool(...)
- Rng::gen_ratio(...) -> Rng::random_ratio(...)
Cargo.toml follow-up
- Update rand = "0.8.x" -> rand = "0.9"
- Update rand = { version = "0.8.x", ... } -> rand = { version = "0.9", ... }
Usage
bash
Manual follow-up
After running, you should:
- Review Cargo.toml updates for uncommon rand dependency formatting not covered by deterministic rewrites
- Run cargo check and cargo test
- Review call sites using custom RNG traits or methods named similarly to gen
- Handle deprecations outside this codemod's deterministic rename scope
Development
bash
References
License
MIT