mirror of
https://github.com/async-rs/async-std.git
synced 2025-03-02 16:19: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(test(attr(allow(unused_extern_crates, unused_variables))))]
|
||||||
#![doc(html_logo_url = "https://async.rs/images/logo--hero.svg")]
|
#![doc(html_logo_url = "https://async.rs/images/logo--hero.svg")]
|
||||||
#![recursion_limit = "1024"]
|
#![recursion_limit = "1024"]
|
||||||
#![feature(try_trait)]
|
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
|
|
|
@ -68,7 +68,6 @@ pub use zip::Zip;
|
||||||
|
|
||||||
use std::cmp::Ordering;
|
use std::cmp::Ordering;
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::Try;
|
|
||||||
|
|
||||||
use cfg_if::cfg_if;
|
use cfg_if::cfg_if;
|
||||||
|
|
||||||
|
@ -958,14 +957,13 @@ extension_trait! {
|
||||||
# }) }
|
# }) }
|
||||||
```
|
```
|
||||||
"#]
|
"#]
|
||||||
fn try_for_each<F, R>(
|
fn try_for_each<F, E>(
|
||||||
self,
|
self,
|
||||||
f: F,
|
f: F,
|
||||||
) -> impl Future<Output = R> [TryForEeachFuture<Self, F, Self::Item, R>]
|
) -> impl Future<Output = R> [TryForEeachFuture<Self, F, Self::Item, E>]
|
||||||
where
|
where
|
||||||
Self: Sized,
|
Self: Sized,
|
||||||
F: FnMut(Self::Item) -> R,
|
F: FnMut(Self::Item) -> Result<(), E>,
|
||||||
R: Try<Ok = ()>,
|
|
||||||
{
|
{
|
||||||
TryForEeachFuture::new(self, f)
|
TryForEeachFuture::new(self, f)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,4 @@
|
||||||
use std::marker::PhantomData;
|
use std::marker::PhantomData;
|
||||||
use std::ops::Try;
|
|
||||||
use std::pin::Pin;
|
use std::pin::Pin;
|
||||||
|
|
||||||
use crate::future::Future;
|
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
|
where
|
||||||
S: Stream,
|
S: Stream,
|
||||||
S::Item: std::fmt::Debug,
|
S::Item: std::fmt::Debug,
|
||||||
F: FnMut(S::Item) -> R,
|
F: FnMut(S::Item) -> Result<(), E>,
|
||||||
R: Try<Ok = ()>,
|
|
||||||
{
|
{
|
||||||
type Output = R;
|
type Output = Result<(), E>;
|
||||||
|
|
||||||
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
|
||||||
loop {
|
loop {
|
||||||
let item = futures_core::ready!(self.as_mut().stream().poll_next(cx));
|
let item = futures_core::ready!(self.as_mut().stream().poll_next(cx));
|
||||||
|
|
||||||
match item {
|
match item {
|
||||||
None => return Poll::Ready(R::from_ok(())),
|
None => return Poll::Ready(Ok(())),
|
||||||
Some(v) => {
|
Some(v) => {
|
||||||
let res = (self.as_mut().f())(v);
|
let res = (self.as_mut().f())(v);
|
||||||
if let Err(e) = res.into_result() {
|
if let Err(e) = res {
|
||||||
return Poll::Ready(R::from_error(e));
|
return Poll::Ready(Err(e));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue