Why doesn't Ref implement AsRef

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?

I don’t think it’s intentional.

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?

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.

Alright then; I'll move along :stuck_out_tongue:

1 Like

:stuck_out_tongue:

2 Likes

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