use crate::interval::*;
use crate::Intervals;
pub trait IntoIntervals: Sized
where
Self: Intervals,
{
fn into_iter(self) -> IntervalsIntoIter<Self, Self::Endpoint>;
}
impl<I> IntoIntervals for I
where
I: Intervals + Sized,
I::Endpoint: Clone + EndpointToggle,
{
fn into_iter(self) -> IntervalsIntoIter<Self, I::Endpoint> {
IntervalsIntoIter {
it: self,
pos: None,
}
}
}
pub struct IntervalsIntoIter<Itr, E> {
it: Itr,
pos: Option<LeftT<E>>,
}
impl<V, E, It> Iterator for IntervalsIntoIter<It, E>
where
It: Intervals<Endpoint = E, Value = V>,
E: Clone + EndpointToggle,
{
type Item = Interval<E, V>;
fn next(&mut self) -> Option<Self::Item> {
let r = self.it.head(self.pos.clone())?;
self.pos = Some(r.right().into_left().clone());
Some(r)
}
}