Avatar ·

What's the difference between `use` and `extern crate` in Rust?

Hi! I recently started learning Rust and got confused about imports. In some examples I see `extern crate`, and in others — `use`. For example, I'm writing a simple program that uses the `rand` crate to generate random numbers: ```rust // Option 1 extern crate rand; use rand::Rng; fn main() { let mut rng = rand::thread_rng(); let n: u32 = rng.gen_range(1..101); println!("Random number: {}", n); } ``` But I've also seen code where `extern crate` is not used at all, and `use` is written directly: ```rust // Option 2 use rand::Rng; fn main() { let mut rng = rand::thread_rng(); let n: u32 = rng.gen_range(1..101); println!("Random number: {}", n); } ``` Both options work, but I don't understand the difference. When should I write `extern crate`, and when should I just use `use`?