How to fold a vector of &str into a single &str
Hello everybody. I'm currently learning rust and was wondering how I could fold a vector of &str into a single &str
I tried this:
fn main() {
let mut v = vec!["foo","bar","baz"];
let concated : String = v.iter().fold("",|i,j| (i.to_string() + *j).as_slice());
println!("{}",concated)
}
But I get an Error:
<anon>:3:29: 3:85 error: mismatched types: expected `collections::string::String`, found `&str` (expected struct collections::string::String, found &-ptr)
<anon>:3 let concated : String = v.iter().fold("",|i,j| (i.to_string() + *j).as_slice());
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Could you give me a few pointers? (not this kind of pointers)
Posted Jan 13, 2015, 3:20 PM UTC
73
Is .concat what you are looking for?
Thanks a lot! That's what I was looking for.