[Pre-RFC] Implicit number type widening

Agreed. "Index into that array with this u16/u32/..." is a perfectly well-defined operation. It is partial, just like normal indexing. It could be implemented as

fn get<I>(&self, i: I) -> Option<&T> where usize: TryFrom<I> {
  self.get_with_usize(usize::try_from(i)?)
}

If either the cast or the indexing fails, we get None, otherwise we get Some. There is nothing lossy about this.

Is there any situation in which this method would not do what is intended, would lead to subtle bugs or would generally not be desirable? Off the top of my head, I don't see any.

9 Likes