defined variable names more clearly

This commit is contained in:
Wyatt J. Miller 2024-08-02 13:58:11 -04:00
parent 93472dcefa
commit 7b8a4e6360

View File

@ -6,12 +6,12 @@ use std::io::BufReader;
fn main() { fn main() {
let file = File::open("team_names.json").expect("Unable to open JSON"); let file = File::open("team_names.json").expect("Unable to open JSON");
let reader = BufReader::new(file); let reader = BufReader::new(file);
let v: Value = serde_json::from_reader(reader).expect("Unable to parse JSON"); let team_names_json: Value = serde_json::from_reader(reader).expect("Unable to parse JSON");
let team_names = v["team_names"].as_array().unwrap(); let team_names_list = team_names_json["team_names"].as_array().unwrap();
let mut rng = rand::thread_rng(); let mut rng = rand::thread_rng();
if let Some(chosen_name) = team_names.choose(&mut rng) { if let Some(chosen_name) = team_names_list.choose(&mut rng) {
println!("Randomly chosen team name: {}", chosen_name); println!("Randomly chosen team name: {}", chosen_name);
} else { } else {
println!("No team names available"); println!("No team names available");