Why don't trait methods use auto-dereferencing? In the following code we have to write &x
explicitly. We wouldn't have to do that with a method call; why?
struct A;
struct B;
impl From<&A> for B {
fn from(_value: &A) -> Self {
Self
}
}
fn main() {
let x = A;
let y: B = x.into();
}
Errors:
Compiling playground v0.0.1 (/playground)
error[E0277]: the trait bound `A: Into<_>` is not satisfied
--> src/main.rs:12:18
|
12 | let y: B = x.into();
| ^^^^ the trait `Into<_>` is not implemented for `A`
|
= note: required for `A` to implement `Into<B>`
help: consider borrowing here
|
12 | let y: B = (&x).into();
| ++ +
For more information about this error, try `rustc --explain E0277`.
error: could not compile `playground` (bin "playground") due to previous error