Don't force zero-yield stream item type of '()'#62
Don't force zero-yield stream item type of '()'#62SergioBenitez wants to merge 2 commits intotokio-rs:masterfrom
Conversation
95ada81 to
e12dd30
Compare
e12dd30 to
ff477c5
Compare
|
ping @taiki-e |
|
I guess the current behavior is based on |
|
cc @carllerche @Darksonn @Kestrer: any thoughts on this? |
|
As an alternative, we can instead insert: if false {
yield unreachable!();
}Like Sergio's solution it is able to produce a stream of any type, but while it is still breaking it breaks less because the following examples still compile: stream! {};
fn takes_debug(stream: impl Stream<Item = impl Debug>) {}
takes_debug(stream! {}); |
|
@SergioBenitez what do you think about @Kestrer's suggestion? In general, I'm inclined to go in any direction here. It isn't a big deal to push out breaking releases of the |
|
By the way: if you do implement this, use |
For streams that never
yield, the implementation forces theItemtype to be inferred as()with ayieldthat never occurs. This has the consequence of making it impossible to create an empty stream for items of types other than(). That is, to write the function:This is a pragmatic concern. In testing keep-alive heartbeats, I would like, but am unable, to write non-
()streams of the following sort without falling back to a needlessmap(|_| unreachable!()):This is a breaking change with likely minimal impact.
P.S: It would be ideal to address #33 to mitigate this and other type-related issues in the future. Syntax to specify the return type could be: