-
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
RFC for index traits #111
RFC for index traits #111
Conversation
If a type implements Note here that I'm expecting that most indexable types will not support setting a value with an index that is not otherwise valid for use with I'd also like to know how how e.g. |
We could do Yes, I was assuming that index-assign would desugar into the |
My preference is to default to |
It'd be nice to keep around some trait with the same functionality as the current |
I like that. Could that have a default method implementation? Also, let me put forth |
@sfackler I was going to say that there are zero clients of I'm not sure what the right way to handle this is, however. We could conceivably make Theoretically, we could even use this to implement |
I also use it to provide a nice api in rust-postgres: https://github.com/sfackler/rust-postgres/blob/32e6a70e8d8ebb7002be12612a984607eba4d128/src/lib.rs#L1451 |
} | ||
|
||
// self[element] = value | ||
trait IndexSet<E,V> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The summary said IndexAssign
—which is it to be?
For reference, in augmented assignment operators (rust-lang/rust#5992), *Assign
is the direction taken thus far, though that can certainly change
Could not an IndexMove trait be included, which is basically the current |
|
Will this work for |
I was thinking further about how this would work with Teepee’s header representation scheme; I’m presuming that this along with #48 will allow me to use proper index assignation at the least. But I won’t be able to use I think I’m going to be stuck with being able to write |
What about changing the syntax from This would also let Bitv return bool |
On Thu, Jun 12, 2014 at 09:47:08PM -0700, bill-myers wrote:
The problem with this is that indexing expressions are lvalues, I had originally thought we might want to add a fourth kind of Index The other impact of your proposed change, of course, would be to move |
This was discussed today and we decided to merge with just two traits. |
I really would like IndexSet. I don't see a strong rationale in the notes not to include it. |
@wycats mainly because the exact design hasn't been worked out, and we're not letting that get in the way of progress (since having |
Is the current |
Summary
Index
should be split intoIndex
,IndexMut
, andIndexAssign
Motivation
Currently, the
Index
trait is not suitable for most array indexing tasks. The slice functionality cannot be replicated using it, and as a result the newVec
has to use.get()
and.get_mut()
methods.Additionally, this simply follows the
Deref
/DerefMut
split that has been implemented for a while.Detailed design
We split
Index
into three traits (borrowed from @nikomatsakis):Drawbacks
Alternatives
The impact of not doing this is that the
[]
notation will not be available toVec
.Unresolved questions
None that I'm aware of.