Deprecated functions that I can't fix

In one of my personal function libraries I use thread_rng() and gen_range() from the rand crate. Apparently the rand crate has been updated and these two methods and now named rng and random_range respectivly. When I compile my project (that uses that library) I get the following warnings:

warning: use of deprecated function `rand::thread_rng`: renamed to `rng`
   --> /home/jtreagan/programming/rust/mine/lib_jt/src/lib.rs:224:27
    |
224 |         let index = rand::thread_rng().gen_range(0..list.len());
    |                           ^^^^^^^^^^
   
warning: use of deprecated method `rand::Rng::gen_range`: Renamed to `random_range`
   --> /home/jtreagan/programming/rust/mine/lib_jt/src/lib.rs:224:40
    |
224 |         let index = rand::thread_rng().gen_range(0..list.len());

However, when I go into my code for that library and change the names of those methods, the compiler doesn't like it.

So, how do I update my code to match these changes?

BTW, just in case you need it, here's my Cargo.toml for that file:

[package]
name = "lib_jt"
version = "0.1.0"
edition = "2021"

[dependencies]
dialoguer = { version = "0.11.0", features = ["completion"] }
console = "0.15.8"

fltk = { version = "^1.4", features = ["fltk-bundled"] }
rand = "0.9.0-alpha.2"

Posting the error message seems prudent.

1 Like

alpha.2 doesn't have those functions. They're only in beta.0 and beta.1. You shouldn't be getting deprecation warnings at all. I don't know why it would be using a different version of rand, though.

Maybe it's that you need to add the std and std_rng features.

These are in default as the next post says.

Those features are part of default, which the Cargo.toml still has enabled.

1 Like

Ummm......I think I did. Was there something more you were thinking about?

Here it is again, just in case...:

warning: use of deprecated function `rand::thread_rng`: renamed to `rng`
   --> /home/jtreagan/programming/rust/mine/lib_jt/src/lib.rs:224:27
    |
224 |         let index = rand::thread_rng().gen_range(0..list.len());
    |                           ^^^^^^^^^^
   
warning: use of deprecated method `rand::Rng::gen_range`: Renamed to `random_range`
   --> /home/jtreagan/programming/rust/mine/lib_jt/src/lib.rs:224:40
    |
224 |         let index = rand::thread_rng().gen_range(0..list.len());

I tried changing the line in my Cargo.toml to:

rand = "^0.8.5"

and while it compiles fine, I still get those warnings. (I have no idea how I ended up using the alpha version.)

Here's something interesting -- when I build the library by itself from it's own directory, it doesn't give me the warning. When I build my main project that includes this library, then I get the warnings. Strange.

I can just ignore the warnings, but I really should be able to fix the issue. Any more ideas?

I assumed you had made an attempt at changing your code and that there are new error messages based on this...

when I go into my code ... and change the names of those methods, the compiler doesn't like it.

I must have misunderstood.

How is your main project depending on your library? Is it a path dependency?