@@ -6,14 +6,14 @@ use std::{
66 task:: Poll ,
77} ;
88
9- use crate :: generator:: { BundleIterator , BundleStream } ;
9+ use crate :: generator:: BundleIterator ;
1010use chunky_vec:: ChunkyVec ;
1111use futures:: { ready, Stream } ;
1212use pin_cell:: { PinCell , PinMut } ;
1313
1414pub struct Cache < I , R >
1515where
16- I : BundleIterator < R > ,
16+ I : Iterator ,
1717{
1818 iter : RefCell < I > ,
1919 items : UnsafeCell < ChunkyVec < I :: Item > > ,
2222
2323impl < I , R > Cache < I , R >
2424where
25- I : BundleIterator < R > ,
25+ I : Iterator ,
2626{
2727 pub fn new ( iter : I ) -> Self {
2828 Self {
@@ -53,23 +53,28 @@ where
5353 ( * items) . push_get ( new_value)
5454 }
5555 }
56+ }
5657
58+ impl < I , R > Cache < I , R >
59+ where
60+ I : BundleIterator + Iterator ,
61+ {
5762 pub fn prefetch ( & self ) {
5863 self . iter . borrow_mut ( ) . prefetch ( ) ;
5964 }
6065}
6166
6267pub struct CacheIter < ' a , I , R >
6368where
64- I : BundleIterator < R > ,
69+ I : Iterator ,
6570{
6671 cache : & ' a Cache < I , R > ,
6772 curr : usize ,
6873}
6974
7075impl < ' a , I , R > Iterator for CacheIter < ' a , I , R >
7176where
72- I : BundleIterator < R > ,
77+ I : Iterator ,
7378{
7479 type Item = & ' a I :: Item ;
7580
@@ -101,7 +106,7 @@ where
101106
102107impl < ' a , I , R > IntoIterator for & ' a Cache < I , R >
103108where
104- I : BundleIterator < R > ,
109+ I : Iterator ,
105110{
106111 type Item = & ' a I :: Item ;
107112 type IntoIter = CacheIter < ' a , I , R > ;
@@ -118,7 +123,7 @@ where
118123
119124pub struct AsyncCache < S , R >
120125where
121- S : BundleStream < R > ,
126+ S : Stream ,
122127{
123128 stream : PinCell < S > ,
124129 items : UnsafeCell < ChunkyVec < S :: Item > > ,
@@ -127,7 +132,7 @@ where
127132
128133impl < S , R > AsyncCache < S , R >
129134where
130- S : BundleStream < R > ,
135+ S : Stream ,
131136{
132137 pub fn new ( stream : S ) -> Self {
133138 Self {
@@ -165,7 +170,12 @@ where
165170 curr : 0 ,
166171 }
167172 }
173+ }
168174
175+ impl < S , R > AsyncCache < S , R >
176+ where
177+ S : BundleIterator + Stream ,
178+ {
169179 pub fn prefetch ( & self ) {
170180 let pin = unsafe { Pin :: new_unchecked ( & self . stream ) } ;
171181 unsafe { PinMut :: as_mut ( & mut pin. borrow_mut ( ) ) . get_unchecked_mut ( ) } . prefetch ( ) ;
@@ -174,7 +184,7 @@ where
174184
175185impl < S , R > AsyncCache < S , R >
176186where
177- S : BundleStream < R > ,
187+ S : Stream ,
178188{
179189 // Helper function that gets the next value from wrapped stream.
180190 fn poll_next_item ( & self , cx : & mut Context < ' _ > ) -> Poll < Option < S :: Item > > {
@@ -185,15 +195,15 @@ where
185195
186196pub struct AsyncCacheStream < ' a , S , R >
187197where
188- S : BundleStream < R > ,
198+ S : Stream ,
189199{
190200 cache : & ' a AsyncCache < S , R > ,
191201 curr : usize ,
192202}
193203
194204impl < ' a , S , R > Stream for AsyncCacheStream < ' a , S , R >
195205where
196- S : BundleStream < R > ,
206+ S : Stream ,
197207{
198208 type Item = & ' a S :: Item ;
199209
0 commit comments