Conceptual
Login

The Deref Trait

Implementing Deref lets a wrapper type hand out a reference to its inner value via the * operator, and deref coercion automatically converts &Box<T> to &T or &String to &str at call sites. This is what makes smart pointers ergonomic to use as if they were plain references.

Questions this Concept answers

  • Why can a lock guard be used as though it were the locked value itself?