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

Move stream items into tokio-stream #3277

Merged
merged 9 commits into from Dec 16, 2020
Merged

Move stream items into tokio-stream #3277

merged 9 commits into from Dec 16, 2020

Conversation

LucioFranco
Copy link
Member

This change removes all references to Stream from
within the tokio crate and moves them into a new
tokio-stream crate. Most types have had their
impl Stream removed as well in-favor of their
inherent methods.

Closes #2870

This change removes all references to `Stream` from
within the `tokio` crate and moves them into a new
`tokio-stream` crate. Most types have had their
`impl Stream` removed as well in-favor of their
inherent methods.

Closes #2870
@LucioFranco LucioFranco added this to the v1.0 milestone Dec 14, 2020
@LucioFranco LucioFranco requested review from carllerche, Darksonn and a team December 14, 2020 21:11
Comment on lines -130 to +127
rx: Rx,
rx: Pin<Box<dyn Stream<Item = String> + Send>>,
Copy link
Contributor

@Darksonn Darksonn Dec 14, 2020

Choose a reason for hiding this comment

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

This raises a question. The Rx type is not used in a way that expects a Stream, rather just in a way that expects something with a poll_next method. Currently the impl Stream is just removed, and the private poll_recv method is not made public.

What approach should we be taking here? I kinda feel like we should be exposing the poll_recv method, as the type supports it perfectly fine (there is only one receiver, so there are no intrusiveness concerns), but then we have both poll_next and poll_recv when we add back the Stream impl in ≥ half a year.

(edit for future readers: a poll_recv method has since been added)

Copy link
Member

Choose a reason for hiding this comment

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

Does this example need to use poll_* APIs at all?

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, I think we should rewrite it.

@Darksonn
Copy link
Contributor

You're missing the Stream impl for ReadDir.

@Darksonn Darksonn added the A-tokio-stream Area: The tokio-stream crate label Dec 14, 2020
tokio-stream/src/iter.rs Show resolved Hide resolved
tokio-stream/src/iter.rs Outdated Show resolved Hide resolved
Comment on lines +311 to +316
/// // Convert the channels to a `Stream`.
/// let rx1 = Box::pin(async_stream::stream! {
/// while let Some(item) = rx1.recv().await {
/// yield item;
/// }
/// }) as Pin<Box<dyn Stream<Item = usize> + Send>>;
Copy link
Contributor

Choose a reason for hiding this comment

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

I plan to submit a proposal for how to improve this later.

Copy link
Member Author

Choose a reason for hiding this comment

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

What would you change?

tokio-stream/src/stream_map.rs Outdated Show resolved Hide resolved
tokio-stream/src/stream_map.rs Outdated Show resolved Hide resolved
tokio-stream/tests/CONTRIBUTING.md Outdated Show resolved Hide resolved
tokio-stream/src/macros.rs Show resolved Hide resolved
tokio/src/sync/broadcast.rs Outdated Show resolved Hide resolved
Comment on lines +74 to 77
// TODO: could probably avoid this, but why not.
let mut rx = Box::pin(rx);

rt.spawn(async move { while rx.next().await.is_some() {} });
Copy link
Contributor

Choose a reason for hiding this comment

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

To avoid it, you could use tokio::pin!, but it would need to be inside the spawned task. Not that it matters much as it is a test.

tokio/tests/support/mpsc_stream.rs Show resolved Hide resolved
@Darksonn
Copy link
Contributor

The main thing missing before I approve this is a review of the generated rustdoc, but I can't do this yet as it does not currently compile.

Copy link
Member

@carllerche carllerche left a comment

Choose a reason for hiding this comment

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

Looking good. Nothing major stands out. Left a few comments inline. @Darksonn also covered stuff 👍

tokio-stream/Cargo.toml Outdated Show resolved Hide resolved
tokio-stream/src/macros.rs Show resolved Hide resolved
tokio-test/src/io.rs Outdated Show resolved Hide resolved
tokio-test/src/io.rs Outdated Show resolved Hide resolved
@@ -381,10 +381,6 @@ cfg_signal_internal! {
pub(crate) mod signal;
}

cfg_stream! {
pub mod stream;
Copy link
Member

Choose a reason for hiding this comment

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

Question: Should we keep an empty module w/ documentation explaining the stream functionality will return once Stream stabilizes in 1.0 and tokio-stream is the current work around? This way, searching for stream in the API docs will find something.

Copy link
Contributor

Choose a reason for hiding this comment

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

That sounds like a good idea.

Copy link
Member

Choose a reason for hiding this comment

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

We can follow up.

tokio/tests/support/mpsc_stream.rs Show resolved Hide resolved
Copy link
Contributor

@Darksonn Darksonn left a comment

Choose a reason for hiding this comment

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

We might want to coordinate between the text in the tokio::stream module and in tokio-stream/src/lib.rs. Doesn't have to be this PR though.

//! [`tokio::io`]: crate::io
//! [`AsyncRead`]: crate::io::AsyncRead
//! [`AsyncWrite`]: crate::io::AsyncWrite
//! [tokio-util]: https://docs.rs/tokio-util/0.4/tokio_util/codec/index.html
Copy link
Contributor

Choose a reason for hiding this comment

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

The link is broken.

Suggested change
//! [tokio-util]: https://docs.rs/tokio-util/0.4/tokio_util/codec/index.html
//! [`tokio-util`]: https://docs.rs/tokio-util/0.4/tokio_util/codec/index.html

attr(deny(warnings, rust_2018_idioms), allow(dead_code, unused_variables))
))]
#![cfg_attr(docsrs, feature(doc_cfg))]

//! Stream utilities for Tokio.
//!
//! A `Stream` is an asynchronous sequence of values. It can be thought of as
Copy link
Contributor

Choose a reason for hiding this comment

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

Below this line (can't select further down), the crate calls itself a module.

Comment on lines +46 to +47
/// [`mpsc`]: https://docs.rs/tokio/1.0/tokio/sync/mpsc/index.html
/// [`pin!`]: https://docs.rs/tokio/1.0/tokio/macro.pin.html
Copy link
Contributor

Choose a reason for hiding this comment

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

These should work as intra-doc links, no? The tokio-stream crates does depend on tokio.

@carllerche
Copy link
Member

@Darksonn had some additional comments, but they can be addressed later (even post 1.0). As this PR is blocking others, I am going to merge it 👍. Thanks!

@carllerche carllerche merged commit 8efa620 into master Dec 16, 2020
@carllerche carllerche deleted the lucio/remove-stream branch December 16, 2020 04:24
@jonhoo
Copy link
Sponsor Contributor

jonhoo commented Jan 5, 2021

I think @Darksonn's comment from #3277 (comment) was lost -- we're missing an implementation for fs::ReadDir.

@Darksonn
Copy link
Contributor

Darksonn commented Jan 5, 2021

Nah, it's there: https://github.com/tokio-rs/tokio/blob/master/tokio-stream/src/wrappers/read_dir.rs

The docs on docs.rs are just generated wrong in the current version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-stream Area: The tokio-stream crate
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stream: coordinating Tokio 1.0 with the availability of Stream in std
4 participants