-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Add panic-safe indexing methods round 2 #1679
Conversation
I'm in favor of overloading Basically what's going on here is a form of "double dispatch", where the thing we want to call depends on two types (the slice, and the index/range/...). Often when we do double-dispatch, we do it with a single-method trait. So one alternative would be having on trait per method here, which would eliminate one of the main drawbacks of the proposed trait, and would allow us to stabilize. OTOH, that's likely even harder to understand on the docs side. (Update: @sfackler added this as an explicit alternative.) |
I think it may also be worth mentioning a drawback of how the documentation here will get a little worse (as @aturon mentioned). Additionally, these are pretty core types and I'd personally be much more confident if we could try this out at least a little, @sfackler could you prepare a branch with this change that |
Ah right, added a drawback about docs. |
Seems smart. I think this could be more explicit about the final syntax enabled by this change and how it achieves that. There's some indirection here that isn't obvious. What I think this RFC does is make Will this cause any type inference to get worse? |
I'm working on a branch to crater here: https://github.com/sfackler/rust/tree/slice-get-slice |
@brson I'll expand the overview tonight. |
@sfackler awesome, thanks! Feel free to ping me whenever that's ready to go and I'll start a run. |
I have thought from time to time that I would really like to have something like the For example, I often make newtyped indices, and I think I would like to have them work just like other indices. It is possible of course to wrap a |
@alexcrichton ok, I think the branch is ready to go. I ran into run-pass-valgrind failures trying to test it myself, but I don't think that's related to my changes. |
Crater build has been scheduled |
@brson I pushed some additional text - does it seem better now? @nikomatsakis Yep, it does seem like we'd want to stabilize the ability to add indices eventually. I do agree with @aturon that if we did stabilize we'd want to split out a trait per method. I'd be fine doing that now, but it is a slightly bigger surface area. |
@sfackler Yes, awesome. |
🔔 This RFC is now entering its week-long final comment period 🔔 I'll be sure to do a crater run before we move to merge this to ensure there's no accidental breakage |
I'd be personally more in favor of |
Discussed during libs triage yesterday the conclusion was to merge as-is. It'll be good to get the stable interface of these methods out there and before (if ever) stabilizing the backing traits we can always revisit the one or multi-trait question again. Thanks again for the RFC @sfackler! |
This is #1325 with the changes discussed at the bottom of that comment chain applied.