Closed
Description
In most high level languages it's easy to turn a list/array of things into a comma separated string. In Rust there is the connect
method, but it requires the elements to implement the trait std::str::Str
. I would like this method to require std::fmt::Show
instead. Alternatively a join
method with according semantics that requires std::fmt::Show
would suffice.
Currently you have to write:
let xs = [1, 2, 3];
let str_xs: ~[~str] = xs.iter().map(|x| x.to_str()).collect();
println!("xs = {}", str_xs.connect(", "));
let mut ys = Vec::new();
ys.push(4);
ys.push(5);
ys.push(6);
let str_ys: Vec<~str> = ys.iter().map(|y| y.to_str()).collect();
println!("ys = {}", str_ys.connect(", "));
This is pretty horrible. This would be much nicer:
let xs = [1, 2, 3];
println!("xs = {}", xs.connect(", "));
let mut ys = Vec::new();
ys.push(4);
ys.push(5);
ys.push(6);
println!("ys = {}", ys.connect(", "));
Metadata
Metadata
Assignees
Labels
No labels