Skip to content

Commit f4e2302

Browse files
committed
Don't use Try trait, use Result instead
1 parent 66d38f7 commit f4e2302

File tree

3 files changed

+9
-14
lines changed

3 files changed

+9
-14
lines changed

src/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,6 @@
4747
#![doc(test(attr(allow(unused_extern_crates, unused_variables))))]
4848
#![doc(html_logo_url = "https://async.rs/images/logo--hero.svg")]
4949
#![recursion_limit = "1024"]
50-
#![feature(try_trait)]
5150

5251
use cfg_if::cfg_if;
5352

src/stream/stream/mod.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,6 @@ pub use zip::Zip;
6868

6969
use std::cmp::Ordering;
7070
use std::marker::PhantomData;
71-
use std::ops::Try;
7271

7372
use cfg_if::cfg_if;
7473

@@ -958,14 +957,13 @@ extension_trait! {
958957
# }) }
959958
```
960959
"#]
961-
fn try_for_each<F, R>(
960+
fn try_for_each<F, E>(
962961
self,
963962
f: F,
964-
) -> impl Future<Output = R> [TryForEeachFuture<Self, F, Self::Item, R>]
963+
) -> impl Future<Output = R> [TryForEeachFuture<Self, F, Self::Item, E>]
965964
where
966965
Self: Sized,
967-
F: FnMut(Self::Item) -> R,
968-
R: Try<Ok = ()>,
966+
F: FnMut(Self::Item) -> Result<(), E>,
969967
{
970968
TryForEeachFuture::new(self, f)
971969
}

src/stream/stream/try_for_each.rs

+6-8
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use std::marker::PhantomData;
2-
use std::ops::Try;
32
use std::pin::Pin;
43

54
use crate::future::Future;
@@ -29,25 +28,24 @@ impl<S, F, T, R> TryForEeachFuture<S, F, T, R> {
2928
}
3029
}
3130

32-
impl<S, F, R> Future for TryForEeachFuture<S, F, S::Item, R>
31+
impl<S, F, E> Future for TryForEeachFuture<S, F, S::Item, E>
3332
where
3433
S: Stream,
3534
S::Item: std::fmt::Debug,
36-
F: FnMut(S::Item) -> R,
37-
R: Try<Ok = ()>,
35+
F: FnMut(S::Item) -> Result<(), E>,
3836
{
39-
type Output = R;
37+
type Output = Result<(), E>;
4038

4139
fn poll(mut self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Self::Output> {
4240
loop {
4341
let item = futures_core::ready!(self.as_mut().stream().poll_next(cx));
4442

4543
match item {
46-
None => return Poll::Ready(R::from_ok(())),
44+
None => return Poll::Ready(Ok(())),
4745
Some(v) => {
4846
let res = (self.as_mut().f())(v);
49-
if let Err(e) = res.into_result() {
50-
return Poll::Ready(R::from_error(e));
47+
if let Err(e) = res {
48+
return Poll::Ready(Err(e));
5149
}
5250
}
5351
}

0 commit comments

Comments
 (0)