mirror of
https://github.com/async-rs/async-std.git
synced 2025-03-01 07:39:40 +00:00
Don't use Try trait, use Result instead
This commit is contained in:
parent
66d38f7856
commit
f4e2302e7e
3 changed files with 9 additions and 14 deletions
|
@ -47,7 +47,6 @@
|
|||
#![doc(test(attr(allow(unused_extern_crates, unused_variables))))]
|
||||
#![doc(html_logo_url = "https://async.rs/images/logo--hero.svg")]
|
||||
#![recursion_limit = "1024"]
|
||||
#![feature(try_trait)]
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
|
|
|
@ -68,7 +68,6 @@ pub use zip::Zip;
|
|||
|
||||
use std::cmp::Ordering;
|
||||
use std::marker::PhantomData;
|
||||
use std::ops::Try;
|
||||
|
||||
use cfg_if::cfg_if;
|
||||
|
||||
|
@ -958,14 +957,13 @@ extension_trait! {
|
|||
# }) }
|
||||
```
|
||||
"#]
|
||||
fn try_for_each<F, R>(
|
||||
fn try_for_each<F, E>(
|
||||
self,
|
||||
f: F,
|
||||
) -> impl Future<Output = R> [TryForEeachFuture<Self, F, Self::Item, R>]
|
||||
) -> impl Future<Output = R> [TryForEeachFuture<Self, F, Self::Item, E>]
|
||||
where
|
||||
Self: Sized,
|
||||
F: FnMut(Self::Item) -> R,
|
||||
R: Try<Ok = ()>,
|
||||
F: FnMut(Self::Item) -> Result<(), E>,
|
||||
{
|
||||
TryForEeachFuture::new(self, f)
|
||||
}
|
||||
|
|
|
@ -1,5 +1,4 @@
|
|||
use std::marker::PhantomData;
|
||||
use std::ops::Try;
|
||||
use std::pin::Pin;
|
||||
|
||||
use crate::future::Future;
|
||||
|
@ -29,25 +28,24 @@ impl<S, F, T, R> TryForEeachFuture<S, F, T, R> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<S, F, R> Future for TryForEeachFuture<S, F, S::Item, R>
|
||||
impl<S, F, E> Future for TryForEeachFuture<S, F, S::Item, E>
|
||||
where
|
||||
S: Stream,
|
||||
S::Item: std::fmt::Debug,
|
||||
F: FnMut(S::Item) -> R,
|
||||
R: Try<Ok = ()>,
|
||||
F: FnMut(S::Item) -> Result<(), E>,
|
||||
{
|
||||
type Output = R;
|
||||
type Output = Result<(), E>;
|
||||
|
||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||
loop {
|
||||
let item = futures_core::ready!(self.as_mut().stream().poll_next(cx));
|
||||
|
||||
match item {
|
||||
None => return Poll::Ready(R::from_ok(())),
|
||||
None => return Poll::Ready(Ok(())),
|
||||
Some(v) => {
|
||||
let res = (self.as_mut().f())(v);
|
||||
if let Err(e) = res.into_result() {
|
||||
return Poll::Ready(R::from_error(e));
|
||||
if let Err(e) = res {
|
||||
return Poll::Ready(Err(e));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue