Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: Implement Index and IndexMut #190

Open
niluxv opened this issue Jul 14, 2021 · 2 comments · May be fixed by #191
Open

Feature request: Implement Index and IndexMut #190

niluxv opened this issue Jul 14, 2021 · 2 comments · May be fixed by #191

Comments

@niluxv
Copy link

niluxv commented Jul 14, 2021

For code which is generic over the Index or IndexMut traits, it would be helpful if ArrayVec would implement the Index and IndexMut traits (in core::ops). I understand and like that you prefer ArrayVec methods not to panic but rather return a Result or Option, and I see I can use the get and get_mut functions and then unwrap myself, but for code generic over these traits this does not help (much).

Precedence for implementing Index<I> and IndexMut<I> where I: SliceIndex<[T]> (even though the methods may panic):

  • (primitive) arrays
  • std::vec::Vec
  • smallvec::SmallVec (from the popular smallvec crate)
  • tinyvec::ArrayVec (from the tinyvec crate)
@bluss
Copy link
Owner

bluss commented Jul 14, 2021

Now panic or not has nothing to do with it, you can already index arrayvec because it derefs to slice. If possible in a good way, we should impl Index too. The complexity of slice's index impls could make them hard to match(?)

@niluxv niluxv linked a pull request Jul 15, 2021 that will close this issue
@niluxv
Copy link
Author

niluxv commented Jul 15, 2021

you can already index arrayvec because it derefs to slice

Ah, didn't think of that. I created a PR which implements Index and IndexMut (also through).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants