Files
addr2line
adler
anyhow
az
backtrace
bitflags
bstr
byteorder
bytes
cfg_if
csv
csv_core
either
error_chain
ffi_support
foreign_types
foreign_types_shared
getrandom
gimli
gmp_mpfr_sys
hashbrown
ieee754
indexmap
itertools
itoa
lazy_static
libc
log
matrixmultiply
memchr
miniz_oxide
ndarray
ndarray_stats
noisy_float
num
num_bigint
num_complex
num_integer
num_iter
num_rational
num_traits
object
once_cell
openssl
openssl_sys
ppv_lite86
probability
proc_macro2
prost
prost_derive
quote
rand
rand_chacha
rand_core
random
rawpointer
regex_automata
rug
rustc_demangle
ryu
serde
serde_derive
serde_json
smartnoise_ffi
smartnoise_runtime
smartnoise_validator
special
statrs
syn
unicode_xid
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
use std::cmp::Ordering::{Equal, Greater, Less};
use super::size_hint;
use std::iter::Fuse;

use crate::either_or_both::EitherOrBoth;

// ZipLongest originally written by SimonSapin,
// and dedicated to itertools https://github.com/rust-lang/rust/pull/19283

/// An iterator which iterates two other iterators simultaneously
///
/// This iterator is *fused*.
///
/// See [`.zip_longest()`](../trait.Itertools.html#method.zip_longest) for more information.
#[derive(Clone, Debug)]
#[must_use = "iterator adaptors are lazy and do nothing unless consumed"]
pub struct ZipLongest<T, U> {
    a: Fuse<T>,
    b: Fuse<U>,
}

/// Create a new `ZipLongest` iterator.
pub fn zip_longest<T, U>(a: T, b: U) -> ZipLongest<T, U> 
    where T: Iterator,
          U: Iterator
{
    ZipLongest {
        a: a.fuse(),
        b: b.fuse(),
    }
}

impl<T, U> Iterator for ZipLongest<T, U>
    where T: Iterator,
          U: Iterator
{
    type Item = EitherOrBoth<T::Item, U::Item>;

    #[inline]
    fn next(&mut self) -> Option<Self::Item> {
        match (self.a.next(), self.b.next()) {
            (None, None) => None,
            (Some(a), None) => Some(EitherOrBoth::Left(a)),
            (None, Some(b)) => Some(EitherOrBoth::Right(b)),
            (Some(a), Some(b)) => Some(EitherOrBoth::Both(a, b)),
        }
    }

    #[inline]
    fn size_hint(&self) -> (usize, Option<usize>) {
        size_hint::max(self.a.size_hint(), self.b.size_hint())
    }
}

impl<T, U> DoubleEndedIterator for ZipLongest<T, U>
    where T: DoubleEndedIterator + ExactSizeIterator,
          U: DoubleEndedIterator + ExactSizeIterator
{
    #[inline]
    fn next_back(&mut self) -> Option<Self::Item> {
        match self.a.len().cmp(&self.b.len()) {
            Equal => match (self.a.next_back(), self.b.next_back()) {
                (None, None) => None,
                (Some(a), Some(b)) => Some(EitherOrBoth::Both(a, b)),
                // These can only happen if .len() is inconsistent with .next_back()
                (Some(a), None) => Some(EitherOrBoth::Left(a)),
                (None, Some(b)) => Some(EitherOrBoth::Right(b)),
            },
            Greater => self.a.next_back().map(EitherOrBoth::Left),
            Less => self.b.next_back().map(EitherOrBoth::Right),
        }
    }
}

impl<T, U> ExactSizeIterator for ZipLongest<T, U>
    where T: ExactSizeIterator,
          U: ExactSizeIterator
{}