Make a generic function for Index<&I> and Index<I>

The real issue is here: https://github.com/Kerollmops/ripin-rs/issues/9

I am trying to make a method that can get a generic type Index<I> or Index<&I> in parameter, is it possible or not ?
With the help of the AsRef and the Into traits maybe ?

Borrow<T> is implemented for both T and &T, so using that is a possibility. (This is unlike AsRef<T>, which is not implemented for T).

Ho ! You're a gentleman ! Thank you, I will look at this right now.

Hum it seems to be a Trait not adapted for this situation.
I will make a specific Trait to handle my problem (Index<I> and Index<&I>).

for <T: Borrow<I>, I, W: Index<T>> ... or something like that?

1 Like