diff --git a/src/stream/double_ended_stream.rs b/src/stream/double_ended_stream.rs new file mode 100644 index 00000000..2287cc64 --- /dev/null +++ b/src/stream/double_ended_stream.rs @@ -0,0 +1,23 @@ +use crate::stream::Stream; + +use std::pin::Pin; +use std::task::{Context, Poll}; + +/// A stream able to yield elements from both ends. +/// +/// Something that implements `DoubleEndedStream` has one extra capability +/// over something that implements [`Stream`]: the ability to also take +/// `Item`s from the back, as well as the front. +/// +/// [`Stream`]: trait.Stream.html +#[cfg_attr(feature = "docs", doc(cfg(unstable)))] +pub trait DoubleEndedStream: Stream { + /// Removes and returns an element from the end of the stream. + /// + /// Returns `None` when there are no more elements. + /// + /// The [trait-level] docs contain more details. + /// + /// [trait-level]: trait.DoubleEndedStream.html + fn poll_next_back(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll>; +} diff --git a/src/stream/mod.rs b/src/stream/mod.rs index 8dcc6d54..6081912b 100644 --- a/src/stream/mod.rs +++ b/src/stream/mod.rs @@ -21,11 +21,13 @@ //! # }) } //! ``` +pub use double_ended_stream::DoubleEndedStream; pub use empty::{empty, Empty}; pub use once::{once, Once}; pub use repeat::{repeat, Repeat}; pub use stream::{Stream, Take}; +mod double_ended_stream; mod empty; mod once; mod repeat;