let b = Box::new(String::from("1"));
b.to_string();
Here, because the type is wrong, the compiler automatically tries to dereference b by calling b.eref ();
But looking at the &**self in the source code of Box, I really don't understand how it returns a T type.
#[stable(feature = "rust1", since = "1.0.0")]
#[rustc_const_unstable(feature = "const_box", issue = "92521")]
impl<T: ?Sized, A: Allocator> const Deref for Box<T, A> {
type Target = T;
fn deref(&self) -> &T {
&**self
}
}
1, self is an &Box type, *self gets a Box type.
2, **self=>*Box, dereference again, should still call deref? But doesn't that make it infinitely recursive? At least my own smart pointer, written like this, will make infinite recursive errors.
So the second step is not clear here. I hope the big guys can answer my questions, thank you!