Build URL from OsStr & str components?

To properly form a URL from entry.file_name(), which is of std::ffi::os_str::OsStr type, use a match expression as below:

let name = entry.file_name();
let url = match name.to_str() {
        Some(name) =>  format!("{}{}", BASE_URL, name),
        _ => None
};

Issue: To properly form a URL from entry.file_name(), which is of std::ffi::os_str::OsStr type.

Answer:

let name = entry.file_name();
let url = match name.to_str() {
        Some(name) =>  format!("{}{}", BASE_URL, name),
        _ => None
};

Explanation:

The entry.file_name() returns an OsStr type and to properly form a URL, we need to convert it into a str type. The match expression tries to convert the OsStr type into a str type and returns the URL if successful. Otherwise, it returns None. The format! macro is used to concatenate the BASE_URL and name to form the complete URL.