-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Exposing combinators #2723
Comments
IMO, the main benefit for keeping these types private is to reserve the ability to replace them with If reserving the ability to make them It's worth noting that if we want to reserve the ability to use If being able to replace these combinators with |
Note that this issue is specifically about combinators, and that nothing in the list of methods actually returns a |
Whoops! In that case, the motivation for not exposing the combinators that I mentioned doesn't really apply at all. |
As far as I understand, there are at least two things to consider:
Another possibility can be not to use combinators at all and return Edit: ...on second thought the |
This is not critical to solve for 0.3. I am going to punt. |
In the meantime, is there anything users can do to e.g. pass return value of |
Sure, you can use generics to accept any stream. fn takes_stream<S: Stream<Item = ...>>(s: S) {
...
} In the specific case of |
Hi! Until combinators of streams are public, is it possible to write a function that returns a pub fn foo() -> /* what do I put here ? */ {
stream::iter(vec![1, 2, 3]).throttle(Duration::from_secs(1))
} If I try to use a generic type: pub fn foo<S: Stream<Item = i32>>() -> S {
stream::iter(vec![1, 2, 3]).throttle(Duration::from_secs(1))
} I get the error:
I don't understand, why isn't |
Because Returning an pub fn foo() -> impl Stream<Item = i32> {
stream::iter(vec![1, 2, 3]).throttle(Duration::from_secs(1))
} |
Yeah, the throttle stream may not be an |
Ok thank you, I wanted a trait with a method that returns a pub trait MyTrait {
type Stream: Stream<Item = i32>;
fn foo(&self) -> Self::Stream;
} But now I'm stuck on trait implementations, I would have liked to do something like this : pub struct MyStruct {}
impl MyTrait for MyStruct {
type Stream = impl Stream<Item = i32>;
fn foo(&self) -> Self::Stream {
stream::iter(vec![1, 2, 3]).throttle(Duration::from_secs(1))
}
} But Is there another way to have a trait's method returning a |
Rather than returning an |
It works well with a |
Exposing combinators is not a breaking change. I am going to remove the 1.0 tag. |
Is it a good idea in the first place to have these combinators which cause conflicts with |
Tokio aims to provide everything commonly needed to implement an async app with Rust. |
This this a decision you intend to stick to or is that something you might want to reconsider in the future? Reason being I presume most projects will rely on both That said, that's a decision that can be made when time comes to decide whether to expose the combinators, or not. |
Note that with the introduction of the |
Hi, I'd like to be able to call Chain::into_inner() to get back to the two component parts, what's the recommended route to be able to do that? |
Why not outsource this decision to the users of the crate, by having combinators re-exported in a module(s) behind a feature flag? That way those who need access to these types can choose said access with the cost of some extra namespace clutter. I don't really see why this would need to be an API level restriction. |
I am open to exposing the combinators in tokio-stream, but I don't think it makes sense to hide them behind a feature flag. |
This is required for cases where a concrete combinator type must be named for whatever reason (e.g. during a trait implementation where there is nothing else to "attach" a type parameter to). |
We have considered exposing the combinators of streams as well as
AsyncRead
and such. This issue tracks whether we want to do this, however the general opinion has been that they shouldn't be public in v1.0, which is not far away (#2718),even if they are temporarily made public in v0.2.
In particular the return types of the following methods would become public:
StreamExt::chain
StreamExt::filter
StreamExt::filter_map
StreamExt::fuse
StreamExt::map
StreamExt::merge
StreamExt::skip
StreamExt::skip_while
StreamExt::take
StreamExt::take_while
StreamExt::timeout
AsyncReadExt::chain
To avoid cluttering the
stream
module, we could create atokio::stream::adapters
ortokio::stream::combinators
module.A quick overview of pros & cons:
Pros:
Iterator
andRead
combinators public.Cons:
It is worth noting that we already have some public combinators, e.g.
io::Take
andio::StreamReader
, as well as many public leaf-IO resources such asio::Empty
that are in some sense similar to combinators. We should consider moving these into new modules if we do that.The text was updated successfully, but these errors were encountered: