Trait zip_long::Zip

source ·
pub trait Zip: IntoIterator + Sized {
    fn zip_fill<R, F>(
        self,
        r: R,
        fill: F
    ) -> Filler<Self::IntoIter, R::IntoIter, F>
    where
        R: IntoIterator<Item = Self::Item>,
        F: FnMut() -> Self::Item
, { ... } fn zip_fill_default<R>(
        self,
        r: R
    ) -> Filler<Self::IntoIter, R::IntoIter, fn() -> Self::Item>
    where
        R: IntoIterator<Item = Self::Item>,
        Self::Item: Default
, { ... } fn zip_fill_with<R>(
        self,
        r: R,
        item: Self::Item
    ) -> FillerWith<Self::IntoIter, R::IntoIter>
    where
        R: IntoIterator<Item = Self::Item>,
        Self::Item: Clone
, { ... } }
Expand description

Zip together two iterators, creating a single iterator that yields the item(s) in parallel until the longer iterator is exhausted. Unlike the zip iterator adaptor in ::std::iter, these adaptors yield elements until the LONGER iterator is exhausted.

use zip::Zip;

Provided Methods§

zip together two iterators. when the shorter iterator runs out of items, replace them with fill until the longer iterator is exhausted.

let mut i: u8 = 0;
let filler = || {
   let c = (b'a' + i) as char;
    i += 1;
    c
 };
let want = vec![('A', 'a'), ('B', 'b'), ('C', 'c'), ('D', 'd')];
let got: Vec<(char, char)> = vec!['A', 'B', 'C', 'D'].zip_fill(Vec::new(), filler).collect();
assert_eq!(want, got);

zip together two iterators. when the shorter iterator runs out of items, replace them with T::default until the longer iterator is exhausted.

let want = vec![(1, 2), (3, 4), (5, 6), (0, 8)];
let got: Vec<(usize, usize)> = vec![1, 3, 5].zip_fill_default(vec![2, 4, 6, 8]).collect();
assert_eq!(want, got);

zip together two iterators. when the shorter iterator runs out of items, replace them with clones of item until the longer iterator is exhausted.

let q = vec![0_usize; 4];
let r = vec![1_usize; 7];
let want = vec![(0_usize, 1_usize); 7];
let got: Vec<(usize, usize)> = q.into_iter().zip_fill_with(r, 0).collect();
assert_eq!(want, got);

Implementors§