Skip to content

Option::map_or_else: Show an example of integrating with Result #111702

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

Merged
merged 1 commit into from
Jun 3, 2023

Conversation

cgwalters
Copy link
Contributor

Moving this from rust-lang/libs-team#59 where an API addition was rejected. But I think it's valuable to add this example to the documentation at least.

@rustbot
Copy link
Collaborator

rustbot commented May 18, 2023

r? @Mark-Simulacrum

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels May 18, 2023
@rustbot
Copy link
Collaborator

rustbot commented May 18, 2023

Hey! It looks like you've submitted a new PR for the library teams!

If this PR contains changes to any rust-lang/rust public library APIs then please comment with @rustbot label +T-libs-api -T-libs to tag it appropriately. If this PR contains changes to any unstable APIs please edit the PR description to add a link to the relevant API Change Proposal or create one if you haven't already. If you're unsure where your change falls no worries, just leave it as is and the reviewer will take a look and make a decision to forward on if necessary.

Examples of T-libs-api changes:

  • Stabilizing library features
  • Introducing insta-stable changes such as new implementations of existing stable traits on existing stable types
  • Introducing new or changing existing unstable library APIs (excluding permanently unstable features / features without a tracking issue)
  • Changing public documentation in ways that create new stability guarantees
  • Changing observable runtime behavior of library APIs

@cgwalters
Copy link
Contributor Author

To summarize, this is just documenting an idiom for converting from Option<T> to Result<T, E> with a fallible fallback. I found some instances here: https://sourcegraph.com/search?q=context:global+lang:rust+.map_or_else%28...%2C+Ok%29&patternType=structural&sm=1&groupBy=repo
One instance is https://github.com/bytecodealliance/wasmtime/blob/8756fcf21bc873d1eabf4adc3bd3654862ca3cd1/crates/component-macro/src/bindgen.rs#L160

@rust-log-analyzer

This comment has been minimized.

Moving this from rust-lang/libs-team#59
where an API addition was rejected.  But I think it's valuable
to add this example to the documentation at least.
@cgwalters cgwalters force-pushed the option-map-or-else-with-result branch from 5f53341 to 440912b Compare May 18, 2023 12:02
@Mark-Simulacrum
Copy link
Member

@bors r+ rollup

@bors
Copy link
Collaborator

bors commented Jun 3, 2023

📌 Commit 440912b has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@bors 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 Jun 3, 2023
matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Jun 3, 2023
…result, r=Mark-Simulacrum

Option::map_or_else: Show an example of integrating with Result

Moving this from rust-lang/libs-team#59 where an API addition was rejected.  But I think it's valuable to add this example to the documentation at least.
bors added a commit to rust-lang-ci/rust that referenced this pull request Jun 3, 2023
…iaskrgr

Rollup of 7 pull requests

Successful merges:

 - rust-lang#111659 (suggest `Option::as_deref(_mut)` on type mismatch in option combinator if it passes typeck)
 - rust-lang#111702 (Option::map_or_else: Show an example of integrating with Result)
 - rust-lang#111878 (Fix codegen test suite for bare-metal-like targets)
 - rust-lang#111969 (bootstrap: Make `clean` respect `dry-run`)
 - rust-lang#111998 (Add other workspaces to `linkedProjects` in rust_analyzer_settings)
 - rust-lang#112215 (only suppress coercion error if type is definitely unsized)
 - rust-lang#112231 (Make sure the build.rustc version is either the same or 1 apart (revised))

r? `@ghost`
`@rustbot` modify labels: rollup
@bors bors merged commit 6e024ec into rust-lang:master Jun 3, 2023
@rustbot rustbot added this to the 1.72.0 milestone Jun 3, 2023
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. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants