arrayvec icon indicating copy to clipboard operation
arrayvec copied to clipboard

Implement `Index` and `IndexMut` traits for `ArrayVec`

Open niluxv opened this issue 4 years ago • 4 comments

I didn't have time to add tests to it yet, but this should implement Index<I> and IndexMut<I> where I: SliceIndex<[T]>.

Fixes #190

niluxv avatar Jul 15 '21 07:07 niluxv

Instead of this implementation (self.get[_mut](index).unwrap()) we could also use

self.deref().index[_mut](index)

Maybe that gives better error messages in some situations? I don't know...

niluxv avatar Jul 15 '21 08:07 niluxv

Looks to be in the right direction, that's nice - I'll be a bit unreachable during the summer, but back in a bit

bluss avatar Jul 19 '21 00:07 bluss

No problem.

I changed the implementation as described above because it indeed gives much better error messages on out of bounds errors, and added some tests.

niluxv avatar Jul 24 '21 08:07 niluxv

So I changed the trait bounds as you suggested and just now added implementations to ArrayString analogous to those for ArrayVec. I also removed the documentation I initially added to the Index/IndexMut implementation since the comment on panicing needn't be true for all instantiations of the generic parameter.

niluxv avatar Aug 29 '21 18:08 niluxv