-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
std::iter::Chain should implement ExactSizeIterator when possible #34433
Comments
Is it just
does this nead tests? if so where and how? |
Unfortunately I don't think this is possible because sum of the the |
On that note, surely // Ranges of u64 and i64 are excluded because they cannot guarantee having
// a length <= usize::MAX, which is required by ExactSizeIterator.
range_exact_iter_impl!(usize u8 u16 u32 isize i8 i16 i32); Seems vaguely related. Would it make sense for |
As @ollie27 noted, this is not possible:
|
It would require changing the contract for ExactSizeIterator, for example:
I don't think such a change affects how this trait can be used in practice today? It would extend its usability. Implementation would be: saturating_add. Note that a longer than maximum chain will of course report its true exact length as soon as enough has been consumed to bring the length down into the usize value range. 5th november: One problem, .chain().rposition() and .chain().enumerate().rev() can have totally wrong results. |
It doesn't seem like this can happen. Is there any hope here or can this be closed? |
I think close. My rationale would be that ExactSizeIterator was introduced to be able to move |
This doesn't even work if both iterators reside in memory, e.g. on a 32bit platform:
This produces a chain that is longer than 2**32, too large to be represented in a |
What I mean is that ExactSizeIterator was designed for |
Well, it sounds like people are in agreement here that this can't happen, unfortunately |
This reverts commit 720da34. Unfortunately, iter::chain on two ExactSizeIterators does not produce an ExactSizeIterator, for reasons described here: rust-lang/rust#34433 .
On the other hand there are cases where your iterators all fit into |
This is the third time in 3 years that I have ended up in this issue. Each use case was definitely fine with panicking on overflow. |
880: Port to gfx-hal-0.6 r=kvark a=kvark This got a little more involved than I hoped, because of rust-lang/rust#34433 which is unfortunately closed. Co-authored-by: Dzmitry Malyshau <kvarkus@gmail.com>
Could this instead be a method on |
|
So, this already seems to have been rejected as a PR-- do people feel like this would have any chance of being approved if it had an RFC first? Or maybe people's opinions have changed? Basically wondering what the path forward for this would be. In my latest case for this, I did |
I'm not sure that it would even panic if we left it up to the |
Once we have generic const exprs this could be revisited by having a trait for non-ZST types and then using knowledge that some iterators (slices, vec) and things derived from those can't exceed isize::MAX items for non-ZSTs. |
This reverts commit 9dbde14. Unfortunately, iter::chain on two ExactSizeIterators does not produce an ExactSizeIterator, for reasons described here: rust-lang/rust#34433 .
When both iterators of the chain implement
ExactSizeIterator
, the chain itself should implement that trait as well.The text was updated successfully, but these errors were encountered: