Skip to content

Commit 3a03e95

Browse files
committed
implement DoubleEndedStream
Signed-off-by: Yoshua Wuyts <[email protected]>
1 parent 6f9ec66 commit 3a03e95

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

src/stream/double_ended_stream.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use crate::stream::Stream;
2+
3+
use std::pin::Pin;
4+
use std::task::{Context, Poll};
5+
6+
/// An stream able to yield elements from both ends.
7+
///
8+
/// Something that implements `DoubleEndedStream` has one extra capability
9+
/// over something that implements [`Stream`]: the ability to also take
10+
/// `Item`s from the back, as well as the front.
11+
///
12+
/// [`Stream`]: trait.Stream.html
13+
pub trait DoubleEndedStream: Stream {
14+
/// Removes and returns an element from the end of the stream.
15+
///
16+
/// Returns `None` when there are no more elements.
17+
///
18+
/// The [trait-level] docs contain more details.
19+
///
20+
/// [trait-level]: trait.DoubleEndedStream.html
21+
fn poll_next_back(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>;
22+
}

src/stream/mod.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ pub use empty::{empty, Empty};
2525
pub use once::{once, Once};
2626
pub use repeat::{repeat, Repeat};
2727
pub use stream::{Stream, Take};
28+
pub use double_ended_stream::DoubleEndedStream;
2829

2930
mod empty;
3031
mod once;
3132
mod repeat;
3233
mod stream;
34+
mod double_ended_stream;

0 commit comments

Comments
 (0)