Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Stream::size_hint #1853

Merged
merged 1 commit into from
Sep 3, 2019
Merged

Conversation

taiki-e
Copy link
Member

@taiki-e taiki-e commented Sep 1, 2019

@@ -126,7 +165,7 @@ mod private_try_stream {

/// A convenience for streams that return `Result` values that includes
/// a variety of adapters tailored to such futures.
pub trait TryStream: private_try_stream::Sealed {
pub trait TryStream: Stream + private_try_stream::Sealed {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added this bound because it would be convenient if stream.size_hint() could be called on St: TryStream.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh...

error[E0191]: the value of the associated type `Item` (from the trait `futures_core::stream::Stream`) must be specified
  --> futures/tests/object_safety.rs:20:30
   |
20 |     assert_is_object_safe::<&dyn TryStream<Ok = (), Error = ()>>();
   |                              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ associated type `Item` must be specified

@@ -57,7 +57,7 @@ mod private_try_future {

/// A convenience for futures that return `Result` values that includes
/// a variety of adapters tailored to such futures.
pub trait TryFuture: private_try_future::Sealed {
pub trait TryFuture: Future + private_try_future::Sealed {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added for consistency with TryStream.

Copy link
Member

@yoshuawuyts yoshuawuyts left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm really into this! Similar to Iterator::size_hint and poll_read_vectored this seems like a method that's really useful to significantly help speed up certain code paths!

@cramertj
Copy link
Member

cramertj commented Sep 3, 2019

Nice! Seems like a good easy add.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Consider adding size_hint to Stream
3 participants