-
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
Introduce remaining Index traits #159
Conversation
👍 Overall I think this is good. What happens if |
Yeah, we'd probably want the compiler to forbid "overlapping" definitions. |
fn index<'a>(&'a self, element: E) -> &'a R; | ||
} | ||
|
||
pub trait IndexMut<E, R>: Index<E, R> { |
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.
Why does IndexMut<E, R>
require Index<E, R>
?
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.
For the upgrade mechanism required to fix the DerefMut
-in-immutable-contexts issue.
Or is it downgrade? In any case, one of IndexMut
or Index
is picked, and depending on whether the result is required to be a mutable lvalue (e.g. method call with &mut self
) or not, the operation will be adjusted to use the more appropriate trait.
Why can't My use case is a matrix type defined like so: struct Matrix<T>
{
elems: Vec<Cell<T>>
} |
I don't think we need
|
I'm assuming the lifetime parameter in This option is mentioned briefly in the RFC. @alexcrichton had some concerns about it with respect to how the compiler would decide what I am still a bit concerned with the weirdness of the by-value overload setup, but it's not the end of the world, and it seems to add a lot more flexibility. |
@sfackler: Ah, I apparently didn't understand that you meant in that section. I think if we go down my route, are there any situations where a data structure would want to have overlapping implementations of Also, the lifetime was needed, but with perhaps it's unnecessary now that we have lifetime elision? |
6357402
to
e0acdf4
Compare
This is an important topic, but by now it's clear we won't be getting to this at the moment. I hope we can come back to it shortly after 1.0 though. Postponing along with |
No description provided.