use std::ops::ControlFlow;
use crate::collector::{Collector, CollectorBase};
pub struct AltBreakHint<C, F> {
collector: C,
f: F,
}
impl<C, F> AltBreakHint<C, F> {
pub(in crate::collector) fn new(collector: C, f: F) -> Self {
Self { collector, f }
}
}
impl<C, F> CollectorBase for AltBreakHint<C, F>
where
C: CollectorBase,
F: Fn(&C) -> ControlFlow<()>,
{
type Output = C::Output;
#[inline]
fn finish(self) -> Self::Output {
self.collector.finish()
}
#[inline]
fn break_hint(&self) -> ControlFlow<()> {
(self.f)(&self.collector)
}
}
impl<C, T, F> Collector<T> for AltBreakHint<C, F>
where
C: Collector<T>,
F: Fn(&C) -> ControlFlow<()>,
{
#[inline]
fn collect(&mut self, item: T) -> ControlFlow<()> {
self.collector.collect(item)
}
#[inline]
fn collect_many(&mut self, items: impl IntoIterator<Item = T>) -> ControlFlow<()> {
self.collector.collect_many(items)
}
#[inline]
fn collect_then_finish(self, items: impl IntoIterator<Item = T>) -> Self::Output {
self.collector.collect_then_finish(items)
}
}