arrayset 3.1.1

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

use super::{Compare, Item};

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

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

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

    fn next(&mut self) -> Option<Self::Item> {
        self.0.next().map(|item| match item {
            Item::Left(item) | Item::Right(item) | Item::Both(item) => item,
        })
    }

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

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