arrayset 3.1.1

An array-backed ordered set type.
Documentation
use core::iter::FusedIterator;

use super::{Compare, Item};

#[derive(Debug)]
pub struct Intersection<'a, T>(Compare<'a, T>);

impl<'a, T> Intersection<'a, T> {
    pub fn new(left: &'a [T], right: &'a [T]) -> Self {
        Self(Compare::new(left, right))
    }
}

impl<'a, T> Iterator for Intersection<'a, T>
where
    T: Ord,
{
    type Item = &'a T;

    fn next(&mut self) -> Option<Self::Item> {
        loop {
            match self.0.next() {
                Some(Item::Both(item)) => return Some(item),
                Some(_) => (),
                None => return None,
            }
        }
    }

    fn size_hint(&self) -> (usize, Option<usize>) {
        (0, Some(self.0.left_len().min(self.0.right_len())))
    }
}

impl<'a, T> FusedIterator for Intersection<'a, T> where T: Ord {}