@@ -197,11 +197,13 @@ pub trait RingBufferExt<T>:
197197mod iter {
198198 use crate :: { RingBufferExt , RingBufferRead } ;
199199 use core:: marker:: PhantomData ;
200+ use core:: iter:: FusedIterator ;
200201
201202 /// RingBufferIterator holds a reference to a `RingBufferExt` and iterates over it. `index` is the
202203 /// current iterator position.
203204 pub struct RingBufferIterator < ' rb , T , RB : RingBufferExt < T > > {
204205 obj : & ' rb RB ,
206+ len : usize ,
205207 index : usize ,
206208 phantom : PhantomData < T > ,
207209 }
@@ -211,6 +213,7 @@ mod iter {
211213 pub fn new ( obj : & ' rb RB ) -> Self {
212214 Self {
213215 obj,
216+ len : obj. len ( ) ,
214217 index : 0 ,
215218 phantom : PhantomData :: default ( ) ,
216219 }
@@ -222,14 +225,35 @@ mod iter {
222225
223226 #[ inline]
224227 fn next ( & mut self ) -> Option < Self :: Item > {
225- if self . index < self . obj . len ( ) {
228+ if self . index < self . len {
226229 let res = self . obj . get ( self . index as isize ) ;
227230 self . index += 1 ;
228231 res
229232 } else {
230233 None
231234 }
232235 }
236+
237+ fn size_hint ( & self ) -> ( usize , Option < usize > ) {
238+ ( self . len , Some ( self . len ) )
239+ }
240+ }
241+
242+ impl < ' rb , T : ' rb , RB : RingBufferExt < T > > FusedIterator for RingBufferIterator < ' rb , T , RB > { }
243+
244+ impl < ' rb , T : ' rb , RB : RingBufferExt < T > > ExactSizeIterator for RingBufferIterator < ' rb , T , RB > { }
245+
246+ impl < ' rb , T : ' rb , RB : RingBufferExt < T > > DoubleEndedIterator for RingBufferIterator < ' rb , T , RB > {
247+ #[ inline]
248+ fn next_back ( & mut self ) -> Option < Self :: Item > {
249+ if self . len > 0 && self . index < self . len {
250+ let res = self . obj . get ( ( self . len - 1 ) as isize ) ;
251+ self . len -= 1 ;
252+ res
253+ } else {
254+ None
255+ }
256+ }
233257 }
234258
235259 /// `RingBufferMutIterator` holds a reference to a `RingBufferExt` and iterates over it. `index` is the
0 commit comments