get returns an Option since the vector could potentially not contain that element. If you know it's in the vector you can index it like employees[0].name. If you want to find an employee in the list with a given ID, you would have to iterate, which you can do like employees.iter().find(|&e| e.id == 3) (this also returns an Option, so you'll need to unwrap it or handle the case where it's missing.)
let employees = vec![
Employee { /* ... */ }
];
let first_employee_name = employees[0].name.clone();
Instead of a java-style get method.
For accessing it based on a property, it's really up to how you want to store the data. If you want to pay the cost of having to sort it, you could sort it by id. You could also use a hashmap and use the key as id if it's unique. Or you could just iterate through the array and find it:
let employees = vec![ /* ... */ ];
let with_id_20 = employees
.iter()
.filter(|x| x.id == 20)
.next();
match with_id_20 {
Some(employee) => { /* We found one */ },
None => { /* We didn't find one */ },
}
Additionally, if you want to fallibly acquire an index, and get an Option back, you can use the get method given by its deref into slice, or its get_mut method if you wish to modify it.
You ARE returning values already from the match. but all branches of the match must return the same kind of value. your Some is returning an Employee and None is printing something. They don't match.
You need to explain what you Actually want to happen. Do you want the program to crash if it's a None? or do you want to print then keep going? Of you want it to keep going what do you want 'jhon' to be after the function if it's a 'None'?
Also I don't see how the hashmap helps at all. A Vec is much more suitable here. Are you trying to ensure IDs are unique? In that case a HashMap is okay.