-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Refactoring use common code between option, result and accum #62883
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Stargateur
changed the title
Refactoring use commun code between option, result and accum
Refactoring use common code between option, result and accum
Jul 22, 2019
I get an idea from #58975 (comment) /// An iterator adapter that produces output as long as the underlying
/// iterator produces `Option::Some` values.
pub(crate) struct OptionShunt;
impl OptionShunt
{
/// Process the given iterator as if it yielded a `T` instead of a
/// `Option<T>`. Any `None` value will stop the inner iterator and
/// the overall result will be a `None`.
pub fn process<I, T, F, U, O>(iter: I, f: F) -> Option<U>
where
I: Iterator<Item = Option<T>>,
O: Iterator<Item = Result<T, ()>>,
F: FnMut(&mut ResultShunt<O, ()>) -> U,
{
ResultShunt::process(iter.map(|x| x.ok_or(())), f).ok()
}
} but I don't make it to compile, I don't think it's possible:
Also, I'm not sure it better to do this. |
This comment has been minimized.
This comment has been minimized.
bors
added
the
S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
label
Jul 26, 2019
scottmcm
added
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
and removed
S-waiting-on-author
Status: This is awaiting some action (such as code changes or more information) from the author.
labels
Jul 27, 2019
r? @scottmcm (Per #62459 (comment)) |
This seems like a good simplification to me. And @bors r+ rollup |
📌 Commit 3334802 has been approved by |
bors
added
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
and removed
S-waiting-on-review
Status: Awaiting review from the assignee but also interested parties.
labels
Jul 27, 2019
Centril
added a commit
to Centril/rust
that referenced
this pull request
Jul 28, 2019
…scottmcm Refactoring use common code between option, result and accum `Option` and `Result` have almost exactly the same code that in `accum.rs` that implement `Sum` and `Product`. This PR just move some code to use the same code for all of them. I believe is better to not implement this `Iterator` feature twice. I'm not very familiar with pub visibility hope I didn't make then public. However, maybe these adapters could be useful and we could think to make then pub. rust-lang#59605 rust-lang#11084 r? @pnkfelix
bors
added a commit
that referenced
this pull request
Jul 28, 2019
Rollup of 8 pull requests Successful merges: - #61207 (Allow lifetime elision in `Pin<&(mut) Self>`) - #62074 (squash of all commits for nth_back on ChunksMut) - #62771 (Break dependencies between `syntax_ext` and other crates) - #62883 (Refactoring use common code between option, result and accum) - #62949 (Re-enable assertions in PPC dist builder) - #62996 (tidy: Add a check for inline unit tests) - #63038 (Make more informative error on outer attribute after inner) - #63050 (ci: download awscli from our mirror) Failed merges: r? @ghost
hkBst
added a commit
to hkBst/rust
that referenced
this pull request
Sep 28, 2022
Remove a FIXME whose code got moved away in rust-lang#62883.
matthiaskrgr
added a commit
to matthiaskrgr/rust
that referenced
this pull request
Oct 2, 2022
Remove a FIXME whose code got moved away in rust-lang#62883. Remove a FIXME whose code got moved away in rust-lang#62883.
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Oct 2, 2022
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#102195 (Improve the COPYRIGHT file) - rust-lang#102313 (Update docs so that deprecated method points to relevant method) - rust-lang#102353 (Allow passing rustix_use_libc cfg using RUSTFLAGS) - rust-lang#102405 (Remove a FIXME whose code got moved away in rust-lang#62883.) - rust-lang#102525 (rustdoc: remove orphaned link on array bracket) - rust-lang#102557 (fix issue with x.py setup running into explicit panic) Failed merges: r? `@ghost` `@rustbot` modify labels: rollup
thomcc
pushed a commit
to tcdi/postgrestd
that referenced
this pull request
Feb 10, 2023
Remove a FIXME whose code got moved away in rust-lang/rust#62883.
thomcc
pushed a commit
to tcdi/postgrestd
that referenced
this pull request
Feb 10, 2023
Remove a FIXME whose code got moved away in #62883. Remove a FIXME whose code got moved away in rust-lang/rust#62883.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
S-waiting-on-bors
Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Option
andResult
have almost exactly the same code that inaccum.rs
that implementSum
andProduct
. This PR just move some code to use the same code for all of them. I believe is better to not implement thisIterator
feature twice.I'm not very familiar with pub visibility hope I didn't make then public. However, maybe these adapters could be useful and we could think to make then pub.
#59605
#11084
r? @pnkfelix