Skip to content

Commit

Permalink
stream: add cancel-safety docs to StreamExt::next and try_next (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
guswynn committed May 27, 2022
1 parent 323b63f commit 05cbfae
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tokio-stream/src/stream_ext.rs
Expand Up @@ -113,6 +113,12 @@ pub trait StreamExt: Stream {
/// pinning it to the stack using the `pin_mut!` macro from the `pin_utils`
/// crate.
///
/// # Cancel safety
///
/// This method is cancel safe. The returned future only
/// holds onto a reference to the underlying stream,
/// so dropping it will never lose a value.
///
/// # Examples
///
/// ```
Expand Down Expand Up @@ -149,6 +155,12 @@ pub trait StreamExt: Stream {
/// an [`Option<Result<T, E>>`](Option), making for easy use
/// with the [`?`](std::ops::Try) operator.
///
/// # Cancel safety
///
/// This method is cancel safe. The returned future only
/// holds onto a reference to the underlying stream,
/// so dropping it will never lose a value.
///
/// # Examples
///
/// ```
Expand Down
7 changes: 7 additions & 0 deletions tokio-stream/src/stream_ext/next.rs
Expand Up @@ -8,6 +8,13 @@ use pin_project_lite::pin_project;

pin_project! {
/// Future for the [`next`](super::StreamExt::next) method.
///
/// # Cancel safety
///
/// This method is cancel safe. It only
/// holds onto a reference to the underlying stream,
/// so dropping it will never lose a value.
///
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct Next<'a, St: ?Sized> {
Expand Down
6 changes: 6 additions & 0 deletions tokio-stream/src/stream_ext/try_next.rs
Expand Up @@ -9,6 +9,12 @@ use pin_project_lite::pin_project;

pin_project! {
/// Future for the [`try_next`](super::StreamExt::try_next) method.
///
/// # Cancel safety
///
/// This method is cancel safe. It only
/// holds onto a reference to the underlying stream,
/// so dropping it will never lose a value.
#[derive(Debug)]
#[must_use = "futures do nothing unless you `.await` or poll them"]
pub struct TryNext<'a, St: ?Sized> {
Expand Down

0 comments on commit 05cbfae

Please sign in to comment.