For example, consider the following function that take ownership of a String vector, and return a String vector directly:
fn consume_produce(x : Vec<String>) -> Vec<String> {
x.iter().map(|x| x.to_owned()).collect::<Vec<String>>()
}
Imagine that we can do some other stuff in the map function or after the map. I found that I have to call to_owned()
explicitly. Is there a more conventional or easier way to do something like this? Also as an example, why this doesn't work:
fn consume_produce(x : Vec<String>) -> Vec<String> {
x.iter().map( |x| *x).collect::<Vec<String>>()
}