Skip to content
This repository was archived by the owner on Jan 15, 2025. It is now read-only.

Add a helper to flatten Result<Result<T>> with tokio_util#210

Merged
cgwalters merged 1 commit intoostreedev:mainfrom
cgwalters:spawn-blocking-flatten
Jan 19, 2022
Merged

Add a helper to flatten Result<Result<T>> with tokio_util#210
cgwalters merged 1 commit intoostreedev:mainfrom
cgwalters:spawn-blocking-flatten

Conversation

@cgwalters
Copy link
Copy Markdown
Member

I think this is nicer than having ?? which still looks odd to me,
and we can also drop a map(anyhow::Error::msg) in once place too.

Prep for further work.

Comment on lines +60 to +61
Ok(Ok(v)) => Ok(v),
Ok(Err(e)) => Err(e),
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Couldn't this be written:

Suggested change
Ok(Ok(v)) => Ok(v),
Ok(Err(e)) => Err(e),
Ok(x) => x,

?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah nice! I started to reply "No because..." then I realized if you just look at it, it's clearly true.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In my defense this code was inspired by rust-lang/rust#70142 (comment) but they're trying to support a "flatten with" which we're hardcoding to be anyhow! effectively. This code is also not as general because it requires the inner to be an anyhow::Result today.

I think this is nicer than having `??` which still looks odd to me,
and we can also drop a `map(anyhow::Error::msg)` in once place too.

Prep for further work.
@cgwalters cgwalters force-pushed the spawn-blocking-flatten branch from 3feb966 to 92c3303 Compare January 19, 2022 19:07
@cgwalters cgwalters merged commit 67ffb88 into ostreedev:main Jan 19, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants