What is the equivalent of the join operator over a vector of Strings?

In Rust 1.3.0 and later, join is available:

fn main() {
    let string_list = vec!["Foo".to_string(),"Bar".to_string()];
    let joined = string_list.join("-");
    assert_eq!("Foo-Bar", joined);
}

Before 1.3.0 this method was called connect:

let joined = string_list.connect("-");

Note that you do not need to import anything since the methods are automatically imported by the standard library prelude.

Leave a Comment