Skip to content

Commit e060326

Browse files
Merge #177
177: implement DoubleEndedStream r=yoshuawuyts a=yoshuawuyts Ref #129. This is the most basic version of the `DoubleEndedStream` trait. Because there is no counterpart in `futures-rs` we allow this to be implementable (not sure if we should though?). This is not a high-priority trait to implement, with probably the most useful addition being the blanket impl over [`std::iter::Fuse`](https://doc.rust-lang.org/std/iter/struct.Fuse.html) (where we should have a `Fuse` counterpart for `Stream` also). So I'm taking this one step at the time, and this PR introduces just the bare minimum to get things working. Thanks! r? @stjepang @taiki-e ## Refs - https://doc.rust-lang.org/std/iter/trait.DoubleEndedIterator.html - #129 Co-authored-by: Yoshua Wuyts <[email protected]>
2 parents 3054509 + fda74ac commit e060326

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

src/stream/double_ended_stream.rs

+23
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
use crate::stream::Stream;
2+
3+
use std::pin::Pin;
4+
use std::task::{Context, Poll};
5+
6+
/// A 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+
#[cfg_attr(feature = "docs", doc(cfg(unstable)))]
14+
pub trait DoubleEndedStream: Stream {
15+
/// Removes and returns an element from the end of the stream.
16+
///
17+
/// Returns `None` when there are no more elements.
18+
///
19+
/// The [trait-level] docs contain more details.
20+
///
21+
/// [trait-level]: trait.DoubleEndedStream.html
22+
fn poll_next_back(self: Pin<&mut Self>, cx: &mut Context<'_>) -> Poll<Option<Self::Item>>;
23+
}

src/stream/mod.rs

+2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,13 @@
2121
//! # }) }
2222
//! ```
2323
24+
pub use double_ended_stream::DoubleEndedStream;
2425
pub use empty::{empty, Empty};
2526
pub use once::{once, Once};
2627
pub use repeat::{repeat, Repeat};
2728
pub use stream::{Stream, Take};
2829

30+
mod double_ended_stream;
2931
mod empty;
3032
mod once;
3133
mod repeat;

0 commit comments

Comments
 (0)