I just want a space separated String
of the argument variables obtained from std::env::args()
, which I've been creating using the fold
function like this:
std::env::args()
.fold("".to_string(), |accum, s| accum + &s + " ")
However this creates an extra space at the end which is unwanted. I tried using the truncate
function, but truncate
doesn't return a String
, just modifies the existing String
, and also this would require the creation of an intermediate binding in order to use the String
's len()
call to define how long the truncated String
should be (which itself would require an intermediate binding due to Rust's current lexical borrowing rules I believe!)
Or better with Itertools'
format
:Or
If you use Itertools,
join
is useful:In other cases, you may want to use
intersperse
:Note this isn't as efficient as other choices as a
String
is cloned for each iteration.Here is an alternative for