checkito 5.0.0

A safe, efficient and simple QuickCheck-inspired library to generate shrinkable random data mainly oriented towards generative/property/exploratory testing.
Documentation
use crate::{generate::Generate, primitive::Constant, shrink::Shrink, state::State};
use core::marker::PhantomData;

#[derive(Debug)]
pub struct Convert<T: ?Sized, I: ?Sized>(pub(crate) PhantomData<I>, pub(crate) T);

impl<T: Clone, I> Clone for Convert<T, I> {
    fn clone(&self) -> Self {
        Self(PhantomData, self.1.clone())
    }
}

impl<G: Generate + ?Sized, I: From<G::Item>> Generate for Convert<G, I> {
    type Item = I;
    type Shrink = Convert<G::Shrink, I>;

    const CARDINALITY: Option<u128> = G::CARDINALITY;

    fn generate(&self, state: &mut State) -> Self::Shrink {
        Convert(PhantomData, self.1.generate(state))
    }

    fn cardinality(&self) -> Option<u128> {
        self.1.cardinality()
    }
}

impl<S: Shrink, I: From<S::Item>> Shrink for Convert<S, I> {
    type Item = I;

    fn item(&self) -> Self::Item {
        I::from(self.1.item())
    }

    fn shrink(&mut self) -> Option<Self> {
        Some(Self(PhantomData, self.1.shrink()?))
    }
}

impl<C: Constant, I> Constant for Convert<C, I> {
    const VALUE: Self = Self(PhantomData, C::VALUE);
}