I have this code example:
use std::path::{Path, PathBuf};
fn test1(p1: impl AsRef<Path>) {
}
fn test2(p1: &impl AsRef<Path>) {
}
fn test3(p1: PathBuf) {
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let p1: PathBuf = PathBuf::from("/home/path");
test1(&p1); // OK (Why?)
test1(p1); // OK
test2(&p1); // OK
test2(p1); // expected reference
test3(&p1); // expected struct `PathBuf`, found `&PathBuf`
test3(p1); // OK
Ok(())
}
I understand why there are errors on calling test2
and test3
.
But why test1
accepts parameter by reference? Where is this behavior documented?