I am trying to implement something like
struct Student {
name: String,
gpa: f32,
// ...
}
struct StudentList {
items: HashMap<&String, Student>,
}
impl StudentList {
pub fn set(&mut self, student: Student) {
self.items.insert(student.name, student)
}
}
Yet the issue is that if I use &String I need to provide a lifetime. How do I specify the key has the same lifetime as the value?