File tree Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Expand file tree Collapse file tree 2 files changed +52
-0
lines changed Original file line number Diff line number Diff line change 1+ mod next_back;
12mod nth_back;
23mod rfind;
34mod rfold;
45mod try_rfold;
56
7+ use next_back:: NextBackFuture ;
68use nth_back:: NthBackFuture ;
79use rfind:: RFindFuture ;
810use rfold:: RFoldFuture ;
@@ -28,6 +30,37 @@ extension_trait! {
2830 Something else
2931 "# ]
3032 pub trait DoubleEndedStreamExt : crate :: stream:: DoubleEndedStream {
33+ #[ doc = r#"
34+ Advances the stream and returns the next value.
35+
36+ Returns [`None`] when iteration is finished. Individual stream implementations may
37+ choose to resume iteration, and so calling `next()` again may or may not eventually
38+ start returning more values.
39+
40+ [`None`]: https://doc.rust-lang.org/std/option/enum.Option.html#variant.None
41+
42+ # Examples
43+
44+ ```
45+ # fn main() { async_std::task::block_on(async {
46+ #
47+ use async_std::stream::Sample;
48+ use async_std::stream::double_ended::DoubleEndedStreamExt;
49+
50+ let mut s = Sample::from(vec![7u8]);
51+
52+ assert_eq!(s.next().await, Some(7));
53+ assert_eq!(s.next().await, None);
54+ #
55+ # }) }
56+ ```
57+ "# ]
58+ fn next( & mut self ) -> impl Future <Output = Option <Self :: Item >> + ' _ [ NextBackFuture <' _, Self >]
59+ where
60+ Self : Unpin ,
61+ {
62+ NextBackFuture { stream: self }
63+ }
3164
3265 #[ doc = r#"
3366 Returns the nth element from the back of the stream.
Original file line number Diff line number Diff line change 1+ use std:: pin:: Pin ;
2+ use std:: future:: Future ;
3+
4+ use crate :: stream:: DoubleEndedStream ;
5+ use crate :: task:: { Context , Poll } ;
6+
7+ #[ doc( hidden) ]
8+ #[ allow( missing_debug_implementations) ]
9+ pub struct NextBackFuture < ' a , T : Unpin + ?Sized > {
10+ pub ( crate ) stream : & ' a mut T ,
11+ }
12+
13+ impl < T : DoubleEndedStream + Unpin + ?Sized > Future for NextBackFuture < ' _ , T > {
14+ type Output = Option < T :: Item > ;
15+
16+ fn poll ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
17+ Pin :: new ( & mut * self . stream ) . poll_next_back ( cx)
18+ }
19+ }
You can’t perform that action at this time.
0 commit comments