# Compiler doesn't understand generics the way I do

**URL:** <https://users.rust-lang.org/t/compiler-doesnt-understand-generics-the-way-i-do/71734>\
**Category:** uncategorized\
**Created:** [February 13, 2022, 9:28am UTC](https://users.rust-lang.org/t/compiler-doesnt-understand-generics-the-way-i-do/71734 "2022-02-13T09:28:01Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![SkiFire13](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/skifire13/32/17959_2.png) [@SkiFire13](https://users.rust-lang.org/u/SkiFire13)\
**Post date:** [February 14, 2022, 4:56pm UTC](https://users.rust-lang.org/t/compiler-doesnt-understand-generics-the-way-i-do/71734/21 "2022-02-14T16:56:51Z")

</div>

> [@afetisov](#):
>
> Note that most things which are `T: AsRef<Path>` would, in practice, implement `T: Deref<Output=Path>` ,

The stdlib currently has implementations of `AsRef<Path>` for 10 types. One is `Path` and in the remaining 9 only one (`PathBuf`) implements `Deref<Target=Path>`.

---

<div class="post-metadata">

**Author:** ![lambda-fairy](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/lambda-fairy/32/3365_2.png) [@lambda-fairy](https://users.rust-lang.org/u/lambda-fairy)\
**Post date:** [February 16, 2022, 2:59am UTC](https://users.rust-lang.org/t/compiler-doesnt-understand-generics-the-way-i-do/71734/22 "2022-02-16T02:59:30Z")

</div>

Another tradeoff is that `Deref` can only be implemented once, but `AsRef` can be implemented multiple times for the same type. So in the general case the compiler won't know _which_ `.as_ref()` to call.

---

<div class="post-metadata">

**Author:** ![system](https://sea1.discourse-cdn.com/flex019/user_avatar/users.rust-lang.org/system/32/51372_2.png) [@system](https://users.rust-lang.org/u/system)\
**Post date:** [May 17, 2022, 2:59am UTC](https://users.rust-lang.org/t/compiler-doesnt-understand-generics-the-way-i-do/71734/23 "2022-05-17T02:59:32Z")

</div>

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.

[Previous page](https://users.rust-lang.org/t/compiler-doesnt-understand-generics-the-way-i-do/71734.md?page=1)
