-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Change advance(_back)_by to return the remainder instead of the number of processed elements #92284
Conversation
r? @yaahc (rust-highfive has picked a reviewer for you, use r? to override) |
This comment has been minimized.
This comment has been minimized.
27c381e
to
f2beb02
Compare
☔ The latest upstream changes (presumably #92070) made this pull request unmergeable. Please resolve the merge conflicts. |
This was made a That said, I can't find the discussion for why the number returned is the number consumed as opposed to the number unconsumed. Perhaps it could make sense to change it to |
|
It's critical for correctness with unfused iterators, though.
|
But that's already handled by |
Reassigning yaahc's reviews as she has stepped down from the review rotation. r? rust-lang/libs-api |
That's only if It doesn't help for |
@the8472 any updates on this pr? |
I'll give this a stab.
|
8b2cf20
to
3dbf7ac
Compare
Hey! It looks like you've submitted a new PR for the library teams! If this PR contains changes to any Examples of
|
usize
instead of Result<(), usize>
From a quick scan this looks good. I'll try to do a proper review later today. How much ACP-age would be expected for this? Am I allowed to just |
No idea. I find the Result + NonZeroUsize a bit wordy for what it does, so maybe that warrants some discussion. Then again, it's only chafing because I had to rewrite that dozens of times 😫 |
library/core/tests/slice.rs
Outdated
assert_eq!(iter.as_slice(), &v[i..]); | ||
} | ||
|
||
let mut iter = v.iter(); | ||
assert_eq!(iter.advance_by(v.len() + 1), Err(v.len())); | ||
assert_eq!(iter.advance_by(v.len() + 1), Err(NonZeroUsize::new(1).unwrap())); |
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.
nit: looks like this got an extra space, which I'm surprised tidy is happyabout
assert_eq!(iter.advance_by(v.len() + 1), Err(NonZeroUsize::new(1).unwrap())); | |
assert_eq!(iter.advance_by(v.len() + 1), Err(NonZeroUsize::new(1).unwrap())); |
|
…ze>` A successful advance is now signalled by returning `0` and other values now represent the remaining number of steps that couldn't be advanced as opposed to the amount of steps that have been advanced during a partial advance_by. This simplifies adapters a bit, replacing some `match`/`if` with arithmetic. Whether this is beneficial overall depends on whether `advance_by` is mostly used as a building-block for other iterator methods and adapters or whether we also see uses by users where `Result` might be more useful.
b8aa679
to
4180793
Compare
This comment was marked as duplicate.
This comment was marked as duplicate.
@bors r=scottmcm |
Rollup of 8 pull requests Successful merges: - rust-lang#91793 (socket ancillary data implementation for FreeBSD (from 13 and above).) - rust-lang#92284 (Change advance(_back)_by to return the remainder instead of the number of processed elements) - rust-lang#102472 (stop special-casing `'static` in evaluation) - rust-lang#108480 (Use Rayon's TLV directly) - rust-lang#109321 (Erase impl regions when checking for impossible to eagerly monomorphize items) - rust-lang#109470 (Correctly substitute GAT's type used in `normalize_param_env` in `check_type_bounds`) - rust-lang#109562 (Update ar_archive_writer to 0.1.3) - rust-lang#109629 (remove obsolete `givens` from regionck) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
When advance_by can't advance the iterator by the number of requested elements it now returns the amount by which it couldn't be advanced instead of the amount by which it did.
This simplifies adapters like chain, flatten or cycle because the remainder doesn't have to be calculated as the difference between requested steps and completed steps anymore.
Additionally switching from
Result<(), usize>
toResult<(), NonZeroUsize>
reduces the size of the result and makes converting from/to a usize representing the number of remaining steps cheap.