@@ -56,15 +56,8 @@ impl<'a, 'py> ValidationState<'a, 'py> {
56
56
& self . extra
57
57
}
58
58
59
- pub fn enumerate_last_partial < ' i , I > (
60
- & self ,
61
- iter : impl Iterator < Item = I > + ' i ,
62
- ) -> Box < dyn Iterator < Item = ( usize , bool , I ) > + ' i > {
63
- if self . allow_partial {
64
- Box :: new ( EnumerateLastPartial :: new ( iter) )
65
- } else {
66
- Box :: new ( iter. enumerate ( ) . map ( |( i, x) | ( i, false , x) ) )
67
- }
59
+ pub fn enumerate_last_partial < I > ( & self , iter : impl Iterator < Item = I > ) -> impl Iterator < Item = ( usize , bool , I ) > {
60
+ EnumerateLastPartial :: new ( iter, self . allow_partial )
68
61
}
69
62
70
63
pub fn strict_or ( & self , default : bool ) -> bool {
@@ -137,14 +130,16 @@ pub struct EnumerateLastPartial<I: Iterator> {
137
130
iter : I ,
138
131
index : usize ,
139
132
next_item : Option < I :: Item > ,
133
+ allow_partial : bool ,
140
134
}
141
135
impl < I : Iterator > EnumerateLastPartial < I > {
142
- pub fn new ( mut iter : I ) -> Self {
136
+ pub fn new ( mut iter : I , allow_partial : bool ) -> Self {
143
137
let next_item = iter. next ( ) ;
144
138
Self {
145
139
iter,
146
140
index : 0 ,
147
141
next_item,
142
+ allow_partial,
148
143
}
149
144
}
150
145
}
@@ -156,7 +151,7 @@ impl<I: Iterator> Iterator for EnumerateLastPartial<I> {
156
151
let a = std:: mem:: replace ( & mut self . next_item , self . iter . next ( ) ) ?;
157
152
let i = self . index ;
158
153
self . index += 1 ;
159
- Some ( ( i, self . next_item . is_none ( ) , a) )
154
+ Some ( ( i, self . allow_partial && self . next_item . is_none ( ) , a) )
160
155
}
161
156
162
157
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
0 commit comments