]>
git.proxmox.com Git - rustc.git/blob - vendor/itertools/src/pad_tail.rs
2 use std
::iter
::{Fuse, FusedIterator}
;
4 /// An iterator adaptor that pads a sequence to a minimum length by filling
5 /// missing elements using a closure.
7 /// Iterator element type is `I::Item`.
9 /// See [`.pad_using()`](crate::Itertools::pad_using) for more information.
11 #[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
12 pub struct PadUsing
<I
, F
> {
19 impl<I
, F
> std
::fmt
::Debug
for PadUsing
<I
, F
>
23 debug_fmt_fields
!(PadUsing
, iter
, min
, pos
);
26 /// Create a new `PadUsing` iterator.
27 pub fn pad_using
<I
, F
>(iter
: I
, min
: usize, filler
: F
) -> PadUsing
<I
, F
>
30 F
: FnMut(usize) -> I
::Item
,
40 impl<I
, F
> Iterator
for PadUsing
<I
, F
>
43 F
: FnMut(usize) -> I
::Item
,
48 fn next(&mut self) -> Option
<Self::Item
> {
49 match self.iter
.next() {
51 if self.pos
< self.min
{
52 let e
= Some((self.filler
)(self.pos
));
66 fn size_hint(&self) -> (usize, Option
<usize>) {
67 let tail
= self.min
.saturating_sub(self.pos
);
68 size_hint
::max(self.iter
.size_hint(), (tail
, Some(tail
)))
72 impl<I
, F
> DoubleEndedIterator
for PadUsing
<I
, F
>
74 I
: DoubleEndedIterator
+ ExactSizeIterator
,
75 F
: FnMut(usize) -> I
::Item
,
77 fn next_back(&mut self) -> Option
<Self::Item
> {
80 } else if self.iter
.len() >= self.min
{
85 Some((self.filler
)(self.min
))
90 impl<I
, F
> ExactSizeIterator
for PadUsing
<I
, F
>
93 F
: FnMut(usize) -> I
::Item
,
97 impl<I
, F
> FusedIterator
for PadUsing
<I
, F
>
100 F
: FnMut(usize) -> I
::Item
,