-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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 FromIterator
and IntoIterator
impls for ThinVec
#83821
Conversation
(rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Do you think it's worth adding a |
Inference was struggling in the |
This comment has been minimized.
This comment has been minimized.
I wouldn't personally add methods that are not used right now, if they can always be added on demand. |
Let me know before you r+ and I can squash. |
This comment has been minimized.
This comment has been minimized.
r=me with commits squashed. |
pub fn new() -> Self { | ||
ThinVec(None) | ||
} | ||
|
||
pub fn iter(&self) -> std::slice::Iter<'_, T> { | ||
self.into_iter() | ||
} | ||
|
||
pub fn iter_mut(&mut self) -> std::slice::IterMut<'_, T> { | ||
self.into_iter() | ||
} | ||
} |
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.
It looks like this is also missing .push
and .pop
, I can add those separately. Seems weird that this derefs to a slice instead of a vec.
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.
You couldn't DerefMut
to a vec in the None case.
These should make using `ThinVec` feel much more like using `Vec`. They will allow users of `Vec` to switch to `ThinVec` while continuing to use `collect()`, `for` loops, and other parts of the iterator API. I don't know if there were use cases before for using the iterator API with `ThinVec`, but I would like to start using `ThinVec` in rustdoc, and having it conform to the iterator API would make the transition *a lot* easier. I added a `FromIterator` impl, an `IntoIterator` impl that yields owned elements, and `IntoIterator` impls that yield immutable or mutable references to elements. I also added some unit tests for `ThinVec`.
@bors r=petrochenkov |
📌 Commit 09ff88b has been approved by |
☀️ Test successful - checks-actions |
These should make using
ThinVec
feel much more like usingVec
.They will allow users of
Vec
to switch toThinVec
while continuingto use
collect()
,for
loops, and other parts of the iterator API.I don't know if there were use cases before for using the iterator API
with
ThinVec
, but I would like to start usingThinVec
in rustdoc,and having it conform to the iterator API would make the transition
a lot easier.
I added a
FromIterator
impl, anIntoIterator
impl that yields ownedelements, and
IntoIterator
impls that yield immutable or mutablereferences to elements. I also added some unit tests for
ThinVec
.