I have a function that takes AsRef<Path>
as an argument and looks like this
fn test<P: AsRef<std::path::Path>>(path: P) {
path.join("13123123");
}
When I compile that, it gives me the following error
error[E0599]: no method named `join` found for type `P` in the current scope
--> src/main.rs:2:10
|
2 | path.join("13123123");
| ^^^^
Try this:
path.as_ref().join("13123123")
see:
fn main() {
let path = std::path::Path::new("./foo/bar/");
test(path);
}
fn test<P: AsRef<std::path::Path>>(path: P) {
println!("{:?}", path.as_ref().join("13123123"));
}
Output:
"./foo/bar/13123123"
See the documentation for AsRef
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With