What I've been told is that once an object (in this cast sth
) implements the Drop
trait then it can use *
operator to call its deref()
method. So I think the result of using *
should be the same as the result of explicitly call deref()
. But I find in some cases the two results are not equal. For example:
use std::ops::Deref;
fn main() {
let sth = Box::new(5);
println!("{:p}", sth.deref());
println!{"{:?}", *sth};
}
I searched the docs and know that the signature of deref()
of Box
is (&self)->&T
. That means it should return a reference of inner value. However, *sth
looks like it is returning the inner value directly. Why are the two results not equal?