177 | fn find_files(res: Vec<Regex>) -> Vec<Path>
| ^^^^^^^^^ doesn't have a size known at compile-time
|
= help: within `Path`, the trait `Sized` is not implemented for `[u8]`
= note: required because it appears within the type `Path`
note: required by a bound in `Vec`
Originally I returned a vector of Strings but since I was going to use them in
for file_name in files {
let file = match File::open(&file_name) {
It felt more efficient to return Path instead since open() takes Path anyway. Is there some clever thing I can do or just go back to returning a vector of strings?
Is there an easy way to convert from Path to PathBuf? (hunting around stackoverflow as I type). Maybe it is why all the examples I've seen convert them to strings via to_lossy_string().
Path::to_path_buf() is what you want. This is the path equivalent of str::to_string() - allocate a new owned buffer to hold a copy of the original data.
There is no difference. There are often multiple ways to write a type conversion, as there are several different traits that deal with converting types as well as intrinsic methods on types for common cases.