1/6

Deref is what makes a smart pointer feel like the thing it wraps. Implementing it gives you two things at once:

  • the * operator
  • deref coercion&Wrapper<T> is accepted where &T is expected, and wrapper.method() finds T's methods
impl<T> Deref for Tracked<T> {
    type Target = T;
    fn deref(&self) -> &T { &self.inner }
}

This is exactly how Box, Rc, Arc, String (to str) and Vec (to [T]) work. There is no compiler magic in any of them.