[Pre-RFC] Add implementation impl<T, U> Borrow<T> for Arc<U: Deref<Target=T>> and similar for Rc

Summary

Add new implementation impl<T, U> Borrow<T> for Arc<U: Deref<Target=T>> and similar for Rc

Motivation

Currently collections: BTreeSet and HashMap, when using Arc or Rc as key, need same type as in Arc or Rc to be used in get function. It is not allowed for value of deferred type to be passed to get as argument.

There's already a Borrow<T> for Arc<T> that is not a subset of your suggestion, and would conflict with your suggestion. And it also conflicts with the existing impl Borrow<U> for U too. Making your suggestion transitive over Borrow instead of Deref resolves the first concern, but not the latter.

Additionally, you can implement

Borrow<LocalType> for Arc<ConcreteTypeBeItLocalOrPrivate>

...which may help your particular use case, but such implementations also conflict with your suggestion.

So it's not possible at this time.

5 Likes

Thank you very much for explanation