This is my code, and this is the error it shows me
error[E0277]: a value of type `std::vec::Vec<&Rol<'_>>` cannot be built from an iterator over elements of type `Rol<'_>`
--> src/main.rs:34:14
|
34 | .collect()
| ^^^^^^^ value of type `std::vec::Vec<&Rol<'_>>` cannot be built from `std::iter::Iterator<Item=Rol<'_>>`
|
= help: the trait `std::iter::FromIterator<Rol<'_>>` is not implemented for `std::vec::Vec<&Rol<'_>>`
error: aborting due to previous error
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground`.
To learn more, run the command again with --verbose.
#[derive(Debug)]
pub struct Employee {
pub name: String,
pub age: i32,
}
pub fn list_employees() -> Vec<Employee> {
let emp1 = Employee {
name: "Jhon".to_string(),
age: 32,
};
let emp2 = Employee {
name: "Smith".to_string(),
age: 32,
};
vec![emp1, emp2]
}
#[derive(Debug)]
pub struct Rol<'a> {
pub employee: &'a Employee,
pub rol: String,
}
impl<'a> Rol<'a> {
pub fn list_roles() -> Vec<&'a Rol<'a>> {
list_employees()
.iter()
.map(|&user| Rol {
employee: &user,
rol: "User".to_string(),
})
.collect()
}
}
pub fn main() {
let list = Rol::list_roles();
println!("roles {:?}", list);
}