Split a string and concat with other inputs

consider a function in which we get a baseurl and a collection of files as a comma-delimited string

fn get_file_list(base_url:&str, file_list: &str, extension: &str) -> Vec<String> {
   // This gives me the expected vector of &str
    let paths = file_list.split(",");
   // example input: 
   // ("http://www.example.com", "one,two", ".png")
   // I want the result to be ["http://www.example.com/one.png", "http://www.example.com/two.png"]
}

Seems so simple but I'm having trouble getting the compiler to work. Any help?

fn get_file_list(base_url: &str, file_list: &str, extension: &str) -> Vec<String> {
    // example input:
    // ("http://www.example.com", "one,two", ".png")
    // I want the result to be ["http://www.example.com/one.png", "http://www.example.com/two.png"]

    file_list
        .split(",")
        .map(|file| [base_url, "/", file, extension].concat())
        .collect()
}

fn main() {
    dbg!(get_file_list("http://www.example.com", "one,two", ".png"));
}
[src/main.rs:13] get_file_list("http://www.example.com", "one,two", ".png") = [
    "http://www.example.com/one.png",
    "http://www.example.com/two.png",
]

Rust Playground

2 Likes

Many thanks!