This program takes as input a sentence " Add name to dept", passes the string into a function that splits the string by whitespace into a vector that then is inserted into a hashmap that is suppose to retain the values of name and dept, which it does for 1 input. On the second input only the first word "Add" is printed. Are there any glaring missteps that may cause this odd output?
use std::io; use std::collections::HashMap; fn main() { let mut input = String::new(); let mut db: HashMap<String,String> = HashMap::new(); loop { println!("'Add <name> to <department>'"); io::stdin().read_line(&mut input).expect("Not input"); add_to_hashmap(&input, &mut db); } } fn add_to_hashmap(input: &String, db: &mut HashMap<String,String>){ let v: Vec<&str> = input.split(" ").collect(); db.insert(v[1].to_string(),v[3].to_string()); for (name, dept) in db{ println!("{}, {}", name, dept); } }