Skip to content

Commit 47f1c15

Browse files
committed
removee Box dyn by always using EnumerateLastPartial
1 parent f28aaba commit 47f1c15

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

src/validators/validation_state.rs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,15 +56,8 @@ impl<'a, 'py> ValidationState<'a, 'py> {
5656
&self.extra
5757
}
5858

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)
6861
}
6962

7063
pub fn strict_or(&self, default: bool) -> bool {
@@ -137,14 +130,16 @@ pub struct EnumerateLastPartial<I: Iterator> {
137130
iter: I,
138131
index: usize,
139132
next_item: Option<I::Item>,
133+
allow_partial: bool,
140134
}
141135
impl<I: Iterator> EnumerateLastPartial<I> {
142-
pub fn new(mut iter: I) -> Self {
136+
pub fn new(mut iter: I, allow_partial: bool) -> Self {
143137
let next_item = iter.next();
144138
Self {
145139
iter,
146140
index: 0,
147141
next_item,
142+
allow_partial,
148143
}
149144
}
150145
}
@@ -156,7 +151,7 @@ impl<I: Iterator> Iterator for EnumerateLastPartial<I> {
156151
let a = std::mem::replace(&mut self.next_item, self.iter.next())?;
157152
let i = self.index;
158153
self.index += 1;
159-
Some((i, self.next_item.is_none(), a))
154+
Some((i, self.allow_partial && self.next_item.is_none(), a))
160155
}
161156

162157
fn size_hint(&self) -> (usize, Option<usize>) {

0 commit comments

Comments
 (0)