Skip to content

add stream::FusedStream as "unstable" #326

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

Merged
merged 1 commit into from
Oct 14, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions src/stream/fused_stream.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
use crate::stream::Stream;

/// A stream that always continues to yield `None` when exhausted.
///
/// Calling next on a fused stream that has returned `None` once is guaranteed
/// to return [`None`] again. This trait should be implemented by all streams
/// that behave this way because it allows optimizing [`Stream::fuse`].
///
/// Note: In general, you should not use `FusedStream` in generic bounds if
/// you need a fused stream. Instead, you should just call [`Stream::fuse`]
/// on the stream. If the stream is already fused, the additional [`Fuse`]
/// wrapper will be a no-op with no performance penalty.
///
/// [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.None
/// [`Stream::fuse`]: trait.Stream.html#method.fuse
/// [`Fuse`]: struct.Fuse.html
#[cfg(any(feature = "unstable", feature = "docs"))]
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
pub trait FusedStream: Stream {}

impl<S: FusedStream + ?Sized + Unpin> FusedStream for &mut S {}
2 changes: 2 additions & 0 deletions src/stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ mod repeat;
cfg_if! {
if #[cfg(any(feature = "unstable", feature = "docs"))] {
mod double_ended_stream;
mod fused_stream;
mod extend;
mod from_stream;
mod into_stream;
Expand All @@ -45,6 +46,7 @@ cfg_if! {
pub use extend::Extend;
pub use from_stream::FromStream;
pub use into_stream::IntoStream;
pub use fused_stream::FusedStream;

pub use stream::Merge;
}
Expand Down