File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -22,3 +22,31 @@ pub trait DoubleEndedStream: Stream {
2222 /// [trait-level]: trait.DoubleEndedStream.html
2323 fn poll_next_back ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Option < Self :: Item > > ;
2424}
25+
26+ pub struct Sample < T > {
27+ inner : Vec < T > ,
28+ }
29+
30+ impl < T > From < Vec < T > > for Sample < T > {
31+ fn from ( data : Vec < T > ) -> Self {
32+ Sample { inner : data }
33+ }
34+ }
35+
36+ impl < T > Unpin for Sample < T > { }
37+
38+ impl < T > Stream for Sample < T > {
39+ type Item = T ;
40+ fn poll_next ( mut self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Option < Self :: Item > > {
41+ if self . inner . len ( ) > 0 {
42+ return Poll :: Ready ( Some ( self . inner . remove ( 0 ) ) ) ;
43+ }
44+ return Poll :: Ready ( None ) ;
45+ }
46+ }
47+
48+ impl < T > DoubleEndedStream for Sample < T > {
49+ fn poll_next_back ( mut self : Pin < & mut Self > , _cx : & mut Context < ' _ > ) -> Poll < Option < Self :: Item > > {
50+ Poll :: Ready ( self . inner . pop ( ) )
51+ }
52+ }
You can’t perform that action at this time.
0 commit comments