use crate::{ any::Any, array::Array, boxed::Boxed, check::Sizes, collect::Collect, convert::Convert, dampen::Dampen, filter::Filter, filter_map::FilterMap, flatten::Flatten, generate::Generate, keep::Keep, map::Map, primitive::number::Number, same::Same, shrink::Shrinker, size::Size, unify::Unify, }; use core::marker::PhantomData; #[inline] pub const fn same(value: T) -> Same { Same(value) } #[inline] pub const fn any(generators: G) -> Any { Any(generators) } #[inline] pub const fn unify(generator: G) -> Unify { Unify(PhantomData, generator) } #[inline] pub const fn shrinker(generator: G) -> Shrinker { Shrinker(generator) } #[inline] pub const fn map T + Clone>(generator: G, map: F) -> Map { Map(map, generator) } #[inline] pub const fn flat_map T + Clone>( generator: G, map: F, ) -> Flatten> { flatten(self::map(generator, map)) } #[inline] pub const fn flatten(generator: G) -> Flatten where G::Item: Generate, { Flatten(generator) } #[inline] pub const fn filter bool + Clone>( generator: G, filter: F, retries: usize, ) -> Filter { Filter { generator, filter, retries, } } #[inline] pub const fn filter_map Option + Clone>( generator: G, filter: F, retries: usize, ) -> FilterMap { FilterMap { generator, filter, retries, } } #[rustversion::since(1.75)] #[inline] pub const fn boxed(generator: Box) -> Boxed { Boxed::new(generator) } #[rustversion::before(1.75)] #[inline] pub fn boxed(generator: Box) -> Boxed { Boxed::new(generator) } #[inline] pub const fn array(generator: G) -> Array { Array(generator) } #[inline] pub const fn collect, F: FromIterator>( generator: G, count: C, minimum: Option, ) -> Collect { Collect { _marker: PhantomData, count, minimum, generator, } } #[inline] pub const fn size, F: Fn(Sizes) -> S>( generator: G, map: F, ) -> Size { Size(generator, map) } #[inline] pub const fn dampen( generator: G, pressure: f64, deepest: usize, limit: usize, ) -> Dampen { Dampen { pressure, deepest, limit, generator, } } #[inline] pub const fn keep(generator: G) -> Keep { Keep(generator) } #[inline] pub const fn convert>(generator: G) -> Convert { Convert(PhantomData, generator) } #[cfg(feature = "regex")] use crate::regex::{Error, Regex}; #[cfg(feature = "regex")] #[inline] pub fn regex(pattern: &str, repeats: Option) -> Result { Regex::new(pattern, repeats) } /// From `MIN..=MAX`. #[inline] pub const fn number() -> impl Generate { T::FULL } /// From `0..=MAX`. #[inline] pub const fn positive() -> impl Generate { T::POSITIVE } /// From `MIN..=0`. #[inline] pub const fn negative() -> impl Generate { T::NEGATIVE } /// Ascii letters. #[inline] pub const fn letter() -> impl Generate { let generator = unify(any(('a'..='z', 'A'..='Z'))); #[allow(clippy::let_and_return)] generator } /// Ascii digits. #[inline] pub const fn digit() -> impl Generate { let generator = '0'..='9'; #[allow(clippy::let_and_return)] generator } /// Ascii characters. #[inline] pub const fn ascii() -> impl Generate { let generator = 0 as char..=127 as char; #[allow(clippy::let_and_return)] generator } #[inline] pub const fn with T + Clone>(generator: F) -> impl Generate { let generator = map((), move |_| generator()); #[allow(clippy::let_and_return)] generator } #[inline] pub const fn lazy G + Clone>( generator: F, ) -> impl Generate { let generator = flat_map((), move |_| generator()); #[allow(clippy::let_and_return)] generator }