How to use uuid crate in Rust UUID generation

Generate a random UUID in Rust by adding the uuid crate with v4 features and calling Uuid::new_v4().

Add the uuid crate to your Cargo.toml with the v4 feature, then import and call Uuid::new_v4() to generate a random UUID.

use uuid::Uuid;

fn main() {
    let my_uuid = Uuid::new_v4();
    println!("Generated UUID: {my_uuid}");
}

Add this to your Cargo.toml:

[dependencies]
uuid = { version = "1.0", features = ["v4"] }