-
Notifications
You must be signed in to change notification settings - Fork 643
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
Consider additional Async
fns
#124
Comments
If we can convert Pros of having explicit functions:
Cons:
|
I'd personally prefer to avoid these if we can (just cut down on API surface area), but if they're inevitable they're inevitable. My preference would be to go the route of @ipetkov |
@alexcrichton Definitely not advocating against That said, using |
I added this to the 0.2 release awhile back, but I don't think it should block it, we can always add functions at any time. |
I would find an Compare match inner_future.poll().map_err(Into::into) {
Ok(Async::Ready(val)) => transform(val).map(Async::Ready),
Ok(Async::NotReady) => Ok(Async::NotReady),
Err(e) => Err(e),
} to self.inner_future.poll().map_err(Into::into).and_then(|async| async.and_then(transform)) (where |
So far Maybe go for something similar to what got implemented with impl<T, E> Async<Result<T, E>> {
pub fn transpose(self) -> Result<Async<T>, E> {
match self {
Async::Ready(Ok(v)) => Ok(Async::Ready(v)),
Async::Ready(Err(e)) => Err(e),
Async::NotReady => Ok(Async::NotReady),
}
}
} Or with an extension trait: pub trait AsyncResultExt<T, E> {
fn transpose(self) -> Result<futures::Async<T>, E>;
}
impl<T, E> AsyncResultExt<T, E> for futures::Async<Result<T, E>> {
fn transpose(self) -> Result<futures::Async<T>, E> {
match self {
futures::Async::Ready(Ok(v)) => Ok(futures::Async::Ready(v)),
futures::Async::Ready(Err(e)) => Err(e),
futures::Async::NotReady => Ok(futures::Async::NotReady),
}
}
} I'd use it like self.inner_future.poll()?.map(transform).transpose() Also see Playground. |
I'm gonna close this issue -- folks can feel free to open PRs with specific proposals. |
Off the top of my head, it may be useful to provide:
unwrap
/expect
or some variantOption<T>
.The text was updated successfully, but these errors were encountered: