Deref
Deref is a Rust standard-library trait that defines how a value is dereferenced to access a target value and enables dereference coercions.
Learn Rust in a Month of Lunches
Deref is the Rust standard trait that defines immutable dereferencing and enables automatic dereference coercions for method and field access.
- How it is used
- Enables wrapper types to expose an inner value’s methods without making the inner field public.
- How deep it goes
- Works through a Deref implementation, method calls, and compiler errors, then distinguishes immutable dereferencing from DerefMut.
- Examples
- Uses a number-holding tuple struct, Box comparison, checked subtraction, and a confusing game-character implementation.
- What you can do after
- Build it from scratch for a simple wrapper, access its target’s methods, and recognize when named methods are clearer.
Idiomatic Rust
Deref is a Rust trait that defines how a value can be dereferenced to access a target value through the dereference operator.
- How it is used
- Enables wrapper structs and smart pointers to expose target methods through dereference coercion.
- How deep it goes
- Works through a wrapper implementation and method-call behavior, then identifies consuming-method and mutable-access limits.
- Examples
- Uses a wrapped vector’s `iter()` and `into_iter()` calls, plus a person wrapper whose `len()` call is misleading.
- What you can do after
- Apply it via Rust’s `Deref` trait to expose appropriate wrapper methods and choose explicit methods or traits when coercion obscures intent.
Related concepts
- deref coercionused by · Deref coercion is Rust's automatic conversion of a reference to a wrapper value into a reference to its dereference target when resolving method calls and compatible operations.
- Cowimplemented by · Cow is Rust’s standard-library clone-on-write type, representing either borrowed or owned data and creating owned data when necessary.
- smart pointerimplemented by · A smart pointer is a pointer-like object that manages or mediates access to a referenced resource, often providing ownership, lifetime, or safety behavior.
- associated typeuses · An associated type is a type member declared by a trait or similar abstraction whose concrete type is specified by each implementation.
- polymorphismuses · Polymorphism is a programming-language capability that lets a common interface or operation work with values of different types while allowing behavior to vary by type or implementation.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.

