Skip to content

Commit

Permalink
Ban manual implementation of TryFuture and TryStream
Browse files Browse the repository at this point in the history
  • Loading branch information
taiki-e authored and cramertj committed Aug 5, 2019
1 parent 68fe63d commit 8b72bc9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
10 changes: 9 additions & 1 deletion futures-core/src/future/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,17 @@ where
}
}

mod private_try_future {
use super::Future;

pub trait Sealed {}

impl<F, T, E> Sealed for F where F: ?Sized + Future<Output = Result<T, E>> {}
}

/// A convenience for futures that return `Result` values that includes
/// a variety of adapters tailored to such futures.
pub trait TryFuture {
pub trait TryFuture: private_try_future::Sealed {
/// The type of successful values yielded by this future
type Ok;

Expand Down
10 changes: 9 additions & 1 deletion futures-core/src/stream.rs
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,17 @@ where
}
}

mod private_try_stream {
use super::Stream;

pub trait Sealed {}

impl<S, T, E> Sealed for S where S: ?Sized + Stream<Item = Result<T, E>> {}
}

/// A convenience for streams that return `Result` values that includes
/// a variety of adapters tailored to such futures.
pub trait TryStream {
pub trait TryStream: private_try_stream::Sealed {
/// The type of successful values yielded by this future
type Ok;

Expand Down

0 comments on commit 8b72bc9

Please sign in to comment.