I am wondering why the rust language choose to automatically call box.deref() when using *box and box is a smart pointer. Because box is actually not a reference (& or &mut).
When glancing through rust code, it often leads to confusion whether I am looking at a typical borrow reference or a smart pointer type.
Is there any plan or way to set the default behavior of *box back to *box.deref()??
But * only applies to reference or raw pointers right? Since some documents said rust only has two types of pointers, reference and raw pointers.
ptr: &T
ptr: Box ===>>> NOT Pointer in compiler’s view
ptr: Rc ===>>> NOT Pointer in compiler’s view
ptr: Arc ===>>> NOT Pointer in compiler’s view
ptr: *const T
I think *box.deref() is better in a sense that it makes very clear where the pointer comes from. Saving a few keystrokes but add quite complexity to make code not that readable and make the concept harder to understand. the trait name deref is also misleading since it actually gives a reference back…
Well, shouldn’t smart pointer different from reference and raw pointers? since they own their data and allocate on heap and have extra meta information? And probably internal implementation is very different from others?
a Deref or DerefMut or DerefMove are all much better than use deference * syntax.
mangling the inherently different concepts together is really confusing.
As I see it all those types mean an indirection to the T value, in contrast to a raw T that is directly embedded in the parent structure or on the stack.
And the deference syntax (*) means to follow that indirection.
The entire point of Deref and friends is to make this possible and to make smart pointers feel like raw pointers / references.
This might be a reach, but I'd wager that every single Deref impl in the standard library boils down to "return the pointer stored at (constant field offset)".