Created
January 8, 2026 20:57
-
-
Save orzklv/dc485d4921b59baba87b2cd163d10025 to your computer and use it in GitHub Desktop.
Async .and_then() for your perfectionism!
This file contains hidden or 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
| pub trait AsyncResult<T, E> { | |
| async fn and_then_async<U, F: AsyncFnOnce(T) -> Result<U, E>>(self, op: F) -> Result<U, E>; | |
| } | |
| impl<T, E> AsyncResult<T, E> for std::result::Result<T, E> { | |
| #[inline] | |
| async fn and_then_async<U, F: AsyncFnOnce(T) -> Result<U, E>>(self, op: F) -> Result<U, E> { | |
| match self { | |
| Ok(t) => op(t).await, | |
| Err(e) => Err(e), | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment