odsek 0.1.0

Lazy, pull-based composition of mathematical interval sets with open/closed endpoints, no_std-compatible.
Documentation
use crate::{EndpointToggle, Interval, Intervals, LeftT};

/// An [`Intervals`] stream containing a single [`Interval`].
///
/// This is the simplest way to lift an `Interval` into the `Intervals` trait
/// so it can participate in composition (`&`, `|`, etc.).
pub struct IntervalsSingle<E, V> {
    v: Interval<E, V>,
}

impl<E, V> IntervalsSingle<E, V> {
    /// Wrap a single [`Interval`].
    pub fn new(v: Interval<E, V>) -> Self {
        Self { v }
    }
}

impl<E, V> Intervals for IntervalsSingle<E, V>
where
    E: Clone + EndpointToggle,
    LeftT<E>: Ord,
    V: Copy,
{
    type Endpoint = E;
    type Value = V;

    fn head(
        &mut self,
        pos: Option<LeftT<Self::Endpoint>>,
    ) -> Option<Interval<Self::Endpoint, Self::Value>> {
        match pos {
            Some(p) => {
                if p < self.v.right().into_left() {
                    let r = Interval::new_lr(self.v.left().max(p), self.v.right(), self.v.value());
                    Some(r)
                } else {
                    None
                }
            }
            None => Some(self.v.clone()),
        }
    }
}