I wouldn't use
.deref(), because you have to
use std::ops::Deref for it and that seems just a little bit weird. For the same reason, I wouldn't
use std::ops::Add; foo.add(bar) when I can write
foo + bar. It's extraneous.
Also noteworthy: when
(*x).foo() will always find
T::foo if it exists, whereas
x.deref().foo() will try
<&T>::foo first (this doesn't cause a problem for
clone, because auto-deref tries to match receiver types exactly before taking a reference; but it could go wrong when you are trying to call a method that takes
self and is available on
(*x).clone() I don't have a strong opinion, but I'd lean toward the second one. It seems like situations where
(*x).clone() would be confusing are probably rare. But that's just my opinion.
AsRef is a generic trait and usually you would use that in the context of a generic function that takes something that is only known to implement
AsRef<U>. It's overkill for just dereferencing a smart pointer.
Depending on the semantics you probably want either