Skip to content

Commit 8b72bc9

Browse files
taiki-ecramertj
authored andcommitted
Ban manual implementation of TryFuture and TryStream
1 parent 68fe63d commit 8b72bc9

File tree

2 files changed

+18
-2
lines changed

2 files changed

+18
-2
lines changed

futures-core/src/future/mod.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,17 @@ where
4747
}
4848
}
4949

50+
mod private_try_future {
51+
use super::Future;
52+
53+
pub trait Sealed {}
54+
55+
impl<F, T, E> Sealed for F where F: ?Sized + Future<Output = Result<T, E>> {}
56+
}
57+
5058
/// A convenience for futures that return `Result` values that includes
5159
/// a variety of adapters tailored to such futures.
52-
pub trait TryFuture {
60+
pub trait TryFuture: private_try_future::Sealed {
5361
/// The type of successful values yielded by this future
5462
type Ok;
5563

futures-core/src/stream.rs

+9-1
Original file line numberDiff line numberDiff line change
@@ -112,9 +112,17 @@ where
112112
}
113113
}
114114

115+
mod private_try_stream {
116+
use super::Stream;
117+
118+
pub trait Sealed {}
119+
120+
impl<S, T, E> Sealed for S where S: ?Sized + Stream<Item = Result<T, E>> {}
121+
}
122+
115123
/// A convenience for streams that return `Result` values that includes
116124
/// a variety of adapters tailored to such futures.
117-
pub trait TryStream {
125+
pub trait TryStream: private_try_stream::Sealed {
118126
/// The type of successful values yielded by this future
119127
type Ok;
120128

0 commit comments

Comments
 (0)