I am trying to make a function in Rust that returns a string vector. This is what I have so far:
fn letters() -> Vec<String> {
let mut v = Vec::new();
v.push("a");
v.push("b");
v
}
fn main() {
println!("{:?}", letters());
}
This is the error:
error[E0308]: mismatched types
--> src/main.rs:5:5
|
1 | fn letters() -> Vec<String> {
| ----------- expected `Vec<String>` because of return type
...
5 | v
| ^ expected struct `String`, found `&str`
|
= note: expected struct `Vec<String>`
found struct `Vec<&str>`
I have been struggling with this. It seems that the only way I can solve the problem is by declaring the vector in a different way but I need to declare it the way I did.