I have a Vec
of UUID
's. I want to add comma's between the UUID
's and put the result in between two &str
to create a String
. This is what I have now:
pub fn select_ids(ids: Vec<Uuid>) -> String {
let x: String = ids.into_iter().map(|id| {
id.to_string() + ","
}).collect();
"(".to_owned() + &x + ")"
}
This is my test:
#[test]
fn t() {
let uuid = Uuid::from_str("123e4567-e89b-12d3-a456-426655440000").unwrap();
let x = select_ids(vec!(uuid, uuid.clone()));
assert_eq!(x, "(123e4567-e89b-12d3-a456-426655440000,123e4567-e89b-12d3-a456-426655440000)");
}
It fails with the following:
Expected :(123e4567-e89b-12d3-a456-426655440000,123e4567-e89b-12d3-a456-426655440000)
Actual :(123e4567-e89b-12d3-a456-426655440000,123e4567-e89b-12d3-a456-426655440000,)
Ofcourse I can cut off the last character, but that will fail if the list contains only 1 id. I am wondering if there is a build in option, like Java has (https://www.geeksforgeeks.org/java-8-streams-collectors-joining-method-with-examples/).