Does the function or if statement auto do the convert?
fn main() {
let args = Cli::parse();
open(&args.path) // open require a &str as first param
if &args.path == "-" {} // "-" is &str
}
fn open(filename: &str) {
println!("{}", filename)
}
When you call open(&args.path), where &args.path is a &String and open() accepts a &str and String can dereference to a str, the compiler will automatically dereference the &String for you. This is one of the few implicit type coersions in Rust, and is also referred to as "auto deref".
This thread on auto deref even mentions how the compiler won't automatically dereference when doing pattern matching (i.e. your match situation):
The equality check in your if-statement isn't doing any special conversions.