use crate::BoxIter;
use crate::BoxShrink;
use crate::Shrink;
use std::marker::PhantomData;
pub fn from_fn<E, I, F>(f: F) -> BoxShrink<E>
where
E: Clone + 'static,
I: Iterator<Item = E> + 'static,
F: Fn(E) -> I + Clone + 'static,
{
Box::new(FromFnShrink {
e: PhantomData,
f: move |original| Box::new((f)(original)),
})
}
pub fn from_fn_boxed<E, F>(f: F) -> BoxShrink<E>
where
E: Clone + 'static,
F: Fn(E) -> BoxIter<E> + Clone + 'static,
{
Box::new(FromFnShrink { e: PhantomData, f })
}
#[derive(Clone)]
struct FromFnShrink<E, F>
where
E: Clone + 'static,
F: Fn(E) -> BoxIter<E> + Clone + 'static,
{
e: PhantomData<E>,
f: F,
}
impl<E, F> Shrink<E> for FromFnShrink<E, F>
where
E: Clone + 'static,
F: Fn(E) -> BoxIter<E> + Clone + 'static,
{
fn candidates(&self, original: E) -> BoxIter<E> {
(self.f)(original)
}
}