Skip to content

Commit

Permalink
Update tour-of-rusts-standard-library-traits.md (#40)
Browse files Browse the repository at this point in the history
fix: can _be_ dereferenced
  • Loading branch information
przprz authored May 29, 2021
1 parent f01396c commit 5eaeb1e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion posts/tour-of-rusts-standard-library-traits.md
Original file line number Diff line number Diff line change
Expand Up @@ -2836,7 +2836,7 @@ trait DerefMut: Deref {
}
```

`Deref<Target = T>` types can dereferenced to `T` types using the dereference operator `*`. This has obvious use-cases for smart pointer types like `Box` and `Rc`. However, we rarely see the dereference operator explicitly used in Rust code, and that's because of a Rust feature called _deref coercion_.
`Deref<Target = T>` types can be dereferenced to `T` types using the dereference operator `*`. This has obvious use-cases for smart pointer types like `Box` and `Rc`. However, we rarely see the dereference operator explicitly used in Rust code, and that's because of a Rust feature called _deref coercion_.

Rust automatically dereferences types when they're being passed as function arguments, returned from a function, or used as part of a method call. This is the reason why we can pass `&String` and `&Vec<T>` to functions expecting `&str` and `&[T]` because `String` impls `Deref<Target = str>` and `Vec<T>` impls `Deref<Target = [T]>`.

Expand Down

0 comments on commit 5eaeb1e

Please sign in to comment.