tokio-rs / tokio

A runtime for writing reliable asynchronous applications with Rust. Provides I/O, networking, scheduling, timers, ...
https://tokio.rs
MIT License
26.59k stars 2.45k forks source link

Making the Stream adaptor structures public in tokio-stream #6656

Closed sharpened-nacho closed 3 months ago

sharpened-nacho commented 3 months ago

Is your feature request related to a problem? Please describe.

The StreamExt trait provides the helpful method take, map, and the like on Streams. But the structures themselves (Take, Map, etc.) are not visible outside the crate, as they are not pub use in stream_ext.rs.

Describe the solution you'd like

Making those types public. Their equivalents in std::iter, std::io and tokio::io are public, and the generator structures Once, Empty, Iter, etc. in tokio-stream are public as well.

Describe alternatives you've considered

As mentionned here by @Darksonn, it could be kept private to be able to

use impl Trait as the return value in the extension trait without a breaking change.

Additional context

Original discussion here : https://github.com/tokio-rs/tokio/discussions/6655#discussioncomment-9868556

I am playing around with tonic, and need to name the type of the Stream I use to implement a Server Streaming RPC. So :

impl MyServiceTrait for MyServiceStructure {
    type RpcResponseType = Take<MyStreamType>;

    async fn my_fn(&self, request: ...) -> Result<Response<RpcResponseType>, Status> { ... }
}

and I can't import Take.