Avatar ·

What is the difference between use and extern crate in Rust? When to use what?

Hello, colleagues! I recently started learning Rust and got confused about two key constructs: `use` and `extern crate`. The documentation says they are both related to importing, but I don't understand when to use which. Here is my code: ```rust // This works extern crate rand; use rand::Rng; fn main() { let secret_number = rand::thread_rng().gen_range(1..101); println!("Secret number: {}", secret_number); } ``` But if I write it like this, without `extern crate`: ```rust use rand::Rng; fn main() { let secret_number = rand::thread_rng().gen_range(1..101); println!("Secret number: {}", secret_number); } ``` The compiler complains: `can't find crate for rand`. Why is `use` needed if nothing works without `extern crate`? And conversely — if I write only `extern