4

Tracking issue for Result::cloned, Result::cloned_err, Result::copied, Result::c...

 2 years ago
source link: https://github.com/rust-lang/rust/issues/63168
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

New issue

Tracking issue for Result::cloned, Result::cloned_err, Result::copied, Result::copied_err #63168

Closed

ksqsf opened this issue on Jul 31, 2019 · 9 comments

Comments

Copy link

Contributor

ksqsf commented on Jul 31, 2019

PR

Copy link

Member

alexcrichton commented on Sep 3, 2019

edited

Some unresolved questions for us to resolve while this is unstable:

  • Do *_err method carry their weight?
  • Is it right for cloned to work on Result<&T, E> or should it work on Result<&T, &E>?
  • Should cloned be cloned_ok?

Copy link

Contributor

Fishrock123 commented on Jul 15, 2021

My 2c:

cloned and copied for Result should do the respective operation to either branch, it seems to me that in most cases where you'd need it fro one you'd need it to handle both branches.

I realize this does make the copied one kinda marginal since most errors are unlikely to be Copy, but perhaps there is a workaround in the odd case you'd want to copy and yet be able exclude Err?

Copy link

spinda commented on Sep 28, 2021

edited

I'm in favor of cloned only cloning the Ok side, i.e., going from Result<&T, E> to Result<T, E>. This API mirrors Option::cloned, and I think it's more likely that a function of the form fn do_fallible_thing() -> Option<&T> eventually evolves into fn do_fallible_thing() -> Result<&T, SomeError> than fn do_fallible_thing() -> Result<&T, &SomeError>. It's still the possibly-present success value that you want to clone; the fact that the failure path now carries an error (versus just None) is an incidental detail.

Copy link

Member

matklad commented on Dec 17, 2021

Given that we already have precedent of Result::map, which applies only to Ok, and is named map rather then map_ok, I feel moderately confident that:

  • cloned should only clone &T, not E
  • it should be named cloned, rather than cloned_ok

Not sure about _err variants, but they are stabilizable separately. So, it seems that we potentially can write a stabilization report here and FCP?

Copy link

Contributor

Author

ksqsf commented 29 days ago

Thanks @matklad for bringing the attention. I believe we generally agree on cloned and copied so the _err variants are left out here.

Stabilization Report

Brief summary

  • Add Result::cloned() for converting Result<&T, E> and Result<&mut T, E> into Result<T, E> by cloning the contents of the Ok part.
  • Add Result::copied() for converting Result<&T, E> and Result<&mut T, E> into Result<T, E> by copying the contents of the Ok part.

Test cases

  • Doc tests included in the original PR (#63166).

Documentation

  • Doc comments included in the original PR(#63166).

Things not covered

  • The _err variants are not proposed to be stabilized.

Copy link

Member

joshtriplett commented 29 days ago

Shall we stabilize the cloned and copied methods on Result, per the above stabilization report?

@rfcbot merge

Copy link

rfcbot commented 29 days ago

edited by m-ou-se

Team member @joshtriplett has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

Copy link

rfcbot commented 26 days ago

bellThis is now entering its final comment period, as per the review above. bell

Copy link

rfcbot commented 16 days ago

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

This will be merged soon.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Assignees

No one assigned

Projects

None yet

Milestone

No milestone

Linked pull requests

Successfully merging a pull request may close this issue.

None yet

11 participants

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK