In some project I have such a code:
path.file_stem().unwrap_or(&OsStr::new("")).to_str().unwrap_or("").to_string() + ".srt"
It looks very bad and ugly. Is there a better way to write this?
I would probably extract this to a method which returns Result and add some ? operator magic.
If you’re trying to change the file extension, use https://doc.rust-lang.org/std/path/struct.Path.html#method.with_extension first and then convert to whatever end type you want.