3 ms·
> there's a level of indirection which is abstracted over by the Deref trait. There isn't, though. Box and Rc have the same number of levels of indirection as
by Rusky 8y ago
> there's a level of indirection which is abstracted over by the Deref trait.
There isn't, though. Box and Rc have the same number of levels of indirection as the built-in pointers: one.
The double * you see in the Box source you linked only arises because the deref method takes self by reference, the same way unique_ptr's operator* takes this as a pointer. (And further, that implementation looks circular? I believe that part of Box is still built-in.)
These are both functions that should always be inlined (in fact the unique_ptr implementation I'm looking at goes through at least four functions to retrieve the actual pointer) so any extra address-taking and dereferencing you see is merely compile-time bookkeeping.
- steveklabnik 8y agoIt is! http://manishearth.github.io/blog/2017/01/10/rust-tidbits-box-is-special/ http://manishearth.github.io/blog/2017/01/10/rust-tidbits-bo...