use arbitrary::{Arbitrary, Result, Unstructured};
mod alignment;
mod byte;
mod collections;
mod kmer;
mod math;
mod records;
mod string;
mod types;
pub use alignment::*;
pub use byte::*;
pub use collections::*;
pub use math::*;
pub use records::*;
pub use string::*;
pub use types::*;
pub trait ArbitrarySpecs<'a>: Sized {
type Output;
fn make_arbitrary(&self, u: &mut Unstructured<'a>) -> Result<Self::Output>;
#[inline]
fn make_arbitrary_iter<'b>(&self, u: &'b mut Unstructured<'a>) -> MakeArbitraryIter<'a, 'b, '_, Self> {
MakeArbitraryIter { specs: self, u }
}
}
impl<'a, S> ArbitrarySpecs<'a> for Option<S>
where
S: ArbitrarySpecs<'a, Output: Arbitrary<'a>>,
{
type Output = S::Output;
#[inline]
fn make_arbitrary(&self, u: &mut Unstructured<'a>) -> Result<Self::Output> {
if let Some(specs) = self {
specs.make_arbitrary(u)
} else {
S::Output::arbitrary(u)
}
}
}
#[must_use = "iterators are lazy and do nothing unless consumed"]
pub struct MakeArbitraryIter<'a, 'b, 'c, Specs> {
specs: &'c Specs,
u: &'b mut Unstructured<'a>,
}
impl<'a, Specs: ArbitrarySpecs<'a>> Iterator for MakeArbitraryIter<'a, '_, '_, Specs> {
type Item = Result<Specs::Output>;
#[inline]
fn next(&mut self) -> Option<Result<Specs::Output>> {
let keep_going = self.u.arbitrary().unwrap_or(false);
if keep_going {
Some(self.specs.make_arbitrary(self.u))
} else {
None
}
}
}