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

Update stream rfc #15

Merged
merged 26 commits into from
Jul 29, 2020
Merged
Changes from 1 commit
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
7ede7b7
update terminology to lending stream, rather than detached stream
nellshamrell Jun 30, 2020
3ccfcb0
adds more information on IntoStream trait
nellshamrell Jun 30, 2020
b5f7031
expands on FromStream trait
nellshamrell Jun 30, 2020
f6cd705
add more info on converting between lending streams and non-lending s…
nellshamrell Jun 30, 2020
a6a69a0
even more information about converting Streams to LendingStreams
nellshamrell Jun 30, 2020
81a2d51
adds in information about the next method
nellshamrell Jul 2, 2020
7c95855
Update rfc-drafts/stream.md
nellshamrell Jul 7, 2020
9f6aa05
Update rfc-drafts/stream.md
nellshamrell Jul 7, 2020
1750343
Update rfc-drafts/stream.md
nellshamrell Jul 7, 2020
0050a3e
Update rfc-drafts/stream.md
nellshamrell Jul 7, 2020
9d48ced
Update rfc-drafts/stream.md
nellshamrell Jul 7, 2020
8d19261
Update rfc-drafts/stream.md
nellshamrell Jul 7, 2020
06205c4
adds in info on IntoStream
nellshamrell Jul 7, 2020
d646a7e
adds in more info about generators
nellshamrell Jul 7, 2020
c0bbd43
Update rfc-drafts/stream.md
nellshamrell Jul 9, 2020
8cf7b37
Update rfc-drafts/stream.md
nellshamrell Jul 9, 2020
df39f12
Update rfc-drafts/stream.md
nellshamrell Jul 9, 2020
a13dd48
Update rfc-drafts/stream.md
nellshamrell Jul 9, 2020
e398679
Update rfc-drafts/stream.md
nellshamrell Jul 9, 2020
d41c12b
Update rfc-drafts/stream.md
nellshamrell Jul 9, 2020
ddec9e0
a few clarifications
nellshamrell Jul 9, 2020
4bcc194
fixes name of crate
nellshamrell Jul 10, 2020
6d06d3f
Update rfc-drafts/stream.md
nellshamrell Jul 10, 2020
35efa81
removes unnecessary bullet points
nellshamrell Jul 10, 2020
642935a
Update rfc-drafts/stream.md
nellshamrell Jul 14, 2020
b9c8bff
adds more info based on feedback
nellshamrell Jul 16, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 46 additions & 0 deletions rfc-drafts/stream.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,52 @@ where
}
```

## Next method/struct

We should also implement a next method, similar to [the implementation in the futures crate](https://docs.rs/futures-util/0.3.5/src/futures_util/stream/stream/next.rs.html#10-12).
nellshamrell marked this conversation as resolved.
Show resolved Hide resolved

```rust
/// Future for the [`next`](super::StreamExt::next) method.
nellshamrell marked this conversation as resolved.
Show resolved Hide resolved
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Next<'a, St: ?Sized> {
stream: &'a mut St,
}
nellshamrell marked this conversation as resolved.
Show resolved Hide resolved

impl<St: ?Sized + Unpin> Unpin for Next<'_, St> {}

impl<'a, St: ?Sized + Stream + Unpin> Next<'a, St> {
pub(super) fn new(stream: &'a mut St) -> Self {
Next { stream }
}
}

impl<St: ?Sized + FusedStream + Unpin> FusedFuture for Next<'_, St> {
fn is_terminated(&self) -> bool {
self.stream.is_terminated()
}
}

nellshamrell marked this conversation as resolved.
Show resolved Hide resolved
impl<St: ?Sized + Stream + Unpin> Future for Next<'_, St> {
type Output = Option<St::Item>;

fn poll(
mut self: Pin<&mut Self>,
cx: &mut Context<'_>,
) -> Poll<Self::Output> {
self.stream.poll_next_unpin(cx)
nellshamrell marked this conversation as resolved.
Show resolved Hide resolved
}
}
```

This would allow a user to await on a future:

```rust
while let Some(v) = stream.next().await {

}
```

# Reference-level explanation
[reference-level-explanation]: #reference-level-explanation

Expand Down