Say, I want to pose some abstract questions, if that won't bother anyone:
File open wants a PathBuf object, but create_dir_all wants a string slice. Is this just unintended or uncoordinated design, or is there a philosophical intent for when we should use PathBuf, and when we should use strings. I am, by preference, just a Linux programmer, so I don't tend to care whether something works on other OS environments. Please advise on any level or sub-topic regarding these matters you feel compelled to or that is helpful.
Sorry. I don't need help with the commands. I want insight into the implementation of the functions. Is there a time when we should use &str, and others when we should use &str? It seems like create_dir_all is just as good a place for PathBuf as any other command. This may not be knowledge that is generally available, but it may also be related to coding philosophy on usage.
The only thing the former loses is some calling ergonomics (at the cost of monomorphization) and the only thing the latter loses over the more common version is how pretty the declaration looks.[1]
The inner function defrays monomorphization cost (with this signature, or the common one).
an incredibly horrible metric for API design but actually why it was chosen for std (!), to the detriment of the ecosystem âŠī¸
Your original assumption is wrong. Both std::fs::create_dir_all and std::fs::File::open take a generic argument that looks like P: AsRef<Path>. That is what @vague tried to tell you. As @quinedot pointed out, that can be any of PathBuf, &Path, &str, String, OsString and more.
The inner function part on this is making me feel dumb. I'm sorry. It cannot be using function overloading, but I am probably too tired. Will look again in the morning. Thank you for all this.