-
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
Add Result::cloned{,_err} and Result::copied{,_err} #63166
Conversation
Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @sfackler (or someone else) soon. If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes. Please see the contribution instructions for more information. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
/// assert_eq!(copied, Ok(12)); | ||
/// ``` | ||
#[unstable(feature = "result_copied", reason = "newly added", issue = "63168")] | ||
pub fn copied(self) -> Result<T, E> { |
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.
My gut tells me that this should be called copied_ok
so that there can be a copied
that will copy both sides in one go.
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.
I'm not entirely sure about the usefulness. From my experience, I usually only need copied_ok
and cloned_ok
. But indeed having copied
, copied_ok
, and copied_err
is more consistent. I've added them in the update.
… to copy/clone both Ok and Err
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Is there any context in which cloned_err would be used? |
This reverts commit 6c13081.
@sfackler Actually I didn't think of a single use case. I'd be more than happy if we could remove Introducing |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Yeah, let's remove the error variants. Come to think of it, I'm having a hard time thinking of a context where I had a |
My use case for |
Ping from triage @sfackler any updates on this? Thanks. |
ping @sfackler |
Second ping from triage, @sfackler can you please review this. Thanks |
Ping from triage, requesting a review @rust-lang/libs |
@ksqsf can you resolve the |
@Dylan-DPC Hi, I just ran the tests locally ( |
@bors: r+ This looks good to me to add as unstable. I added some explicit questions to the tracking issue to make sure we get back to them by stabilization. |
📌 Commit 61e5286 has been approved by |
Add Result::cloned{,_err} and Result::copied{,_err} This is a little nice addition to `Result`. 1. I'm not sure how useful are `cloned_err` and `copied_err`, but for the sake of completeness they are here. 2. Naming is similar to `map`/`map_err`. I thought about naming `cloned` as `cloned_ok` and add another method called `cloned` that clones both Ok and Err, but `cloned_ok` should be more prevalent than `cloned_both`.
Rollup of 10 pull requests Successful merges: - #63166 (Add Result::cloned{,_err} and Result::copied{,_err}) - #63930 (Account for doc comments coming from proc macros without spans) - #63985 (Stabilize pin_into_inner in 1.39.0) - #64023 (libstd fuchsia fixes) - #64030 (Fix unlock ordering in SGX synchronization primitives) - #64041 (use TokenStream rather than &[TokenTree] for built-in macros) - #64043 (Add some more tests for underscore imports) - #64092 (Update xLTO compatibility table in rustc book.) - #64120 (Move path parsing earlier) - #64123 (Added warning around code with reference to uninit bytes) Failed merges: r? @ghost
Add Result::cloned{,_err} and Result::copied{,_err} This is a little nice addition to `Result`. 1. I'm not sure how useful are `cloned_err` and `copied_err`, but for the sake of completeness they are here. 2. Naming is similar to `map`/`map_err`. I thought about naming `cloned` as `cloned_ok` and add another method called `cloned` that clones both Ok and Err, but `cloned_ok` should be more prevalent than `cloned_both`.
☀️ Test successful - checks-azure |
This is a little nice addition to
Result
.cloned_err
andcopied_err
, but for the sake of completeness they are here.map
/map_err
. I thought about namingcloned
ascloned_ok
and add another method calledcloned
that clones both Ok and Err, butcloned_ok
should be more prevalent thancloned_both
.