# Why doesn't Ref implement AsRef

**URL:** <https://internals.rust-lang.org/t/why-doesnt-ref-implement-asref/10538>\
**Category:** libs\
**Created:** [July 9, 2019, 6:06pm UTC](https://internals.rust-lang.org/t/why-doesnt-ref-implement-asref/10538 "2019-07-09T18:06:15Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![joshlf](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/joshlf/32/3815_2.png) [@joshlf](https://internals.rust-lang.org/u/joshlf)\
**Post date:** [July 9, 2019, 6:06pm UTC](https://internals.rust-lang.org/t/why-doesnt-ref-implement-asref/10538/1 "2019-07-09T18:06:15Z")

</div>

`Ref<T>` implements `Deref<Target=T>`, but not `AsRef<T>`. Does anyone know whether this was intentional, or just something nobody has so far needed?

---

<div class="post-metadata">

**Author:** ![sfackler](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/sfackler/32/9_2.png) [@sfackler](https://internals.rust-lang.org/u/sfackler)\
**Post date:** [July 9, 2019, 6:28pm UTC](https://internals.rust-lang.org/t/why-doesnt-ref-implement-asref/10538/2 "2019-07-09T18:28:31Z")

</div>

I don’t think it’s intentional.

---

<div class="post-metadata">

**Author:** ![joshlf](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/joshlf/32/3815_2.png) [@joshlf](https://internals.rust-lang.org/u/joshlf)\
**Post date:** [July 9, 2019, 6:31pm UTC](https://internals.rust-lang.org/t/why-doesnt-ref-implement-asref/10538/3 "2019-07-09T18:31:16Z")

</div>

Actually, looking at the docs on some of the other methods:

> This is an associated function that needs to be used as `Ref::map_split(...)` . A method would interfere with methods of the same name on the contents of a `RefCell` used through `Deref` .

So maybe the thinking was that adding the `as_ref` method might be problematic?

---

<div class="post-metadata">

**Author:** ![Centril](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/centril/32/3334_2.png) [@Centril](https://internals.rust-lang.org/u/Centril)\
**Post date:** [July 9, 2019, 7:04pm UTC](https://internals.rust-lang.org/t/why-doesnt-ref-implement-asref/10538/4 "2019-07-09T19:04:12Z")

</div>

> [@joshlf](#):
>
> So maybe the thinking was that adding the `as_ref` method might be problematic?

Worth testing out with crater?

---

<div class="post-metadata">

**Author:** ![joshlf](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/joshlf/32/3815_2.png) [@joshlf](https://internals.rust-lang.org/u/joshlf)\
**Post date:** [July 9, 2019, 7:06pm UTC](https://internals.rust-lang.org/t/why-doesnt-ref-implement-asref/10538/5 "2019-07-09T19:06:19Z")

</div>

> [@Centril](#):
>
> > So maybe the thinking was that adding the `as_ref` method might be problematic?
> 
> Worth testing out with crater?

It was just an idle curiosity. I think the general approach of "don't add methods to types that also implement `Deref`" is reasonable (and, from what I can tell, fairly standard across `std`). I don't have a use case that implies we need to change it.

---

<div class="post-metadata">

**Author:** ![Centril](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/centril/32/3334_2.png) [@Centril](https://internals.rust-lang.org/u/Centril)\
**Post date:** [July 9, 2019, 7:07pm UTC](https://internals.rust-lang.org/t/why-doesnt-ref-implement-asref/10538/6 "2019-07-09T19:07:23Z")

</div>

> [@joshlf](#):
>
> It was just an idle curiosity.

Alright then; I'll move along 😛

---

<div class="post-metadata">

**Author:** ![joshlf](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/joshlf/32/3815_2.png) [@joshlf](https://internals.rust-lang.org/u/joshlf)\
**Post date:** [July 9, 2019, 7:07pm UTC](https://internals.rust-lang.org/t/why-doesnt-ref-implement-asref/10538/7 "2019-07-09T19:07:39Z")

</div>

> [@Centril](#):
>
> > It was just an idle curiosity.
> 
> Alright then; I’ll move along 😛

😛

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/flex002/user_avatar/internals.rust-lang.org/system/32/14092_2.png) [@system](https://internals.rust-lang.org/u/system)\
**Post date:** [October 7, 2019, 7:18pm UTC](https://internals.rust-lang.org/t/why-doesnt-ref-implement-asref/10538/8 "2019-10-07T19:18:57Z")

</div>

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
