pub trait Arbitrary: Sized + Debug {
type Parameters: Default;
type Strategy: Strategy<Value = Self>;
// Required method
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy;
// Provided method
fn arbitrary() -> Self::Strategy { ... }
}
Expand description
Arbitrary determines a canonical Strategy
for the implementing type.
It provides the method arbitrary_with
which generates a Strategy
for
producing arbitrary values of the implementing type (Self
). In general,
these strategies will produce the entire set of values possible for the
type, up to some size limitation or constraints set by their parameters.
When this is not desired, strategies to produce the desired values can be
built by combining Strategy
s as described in the crate documentation.
This trait analogous to
Haskell QuickCheck’s implementation of Arbitrary
.
In this interpretation of Arbitrary
, Strategy
is the equivalent of
the Gen
monad. Unlike in QuickCheck, Arbitrary
is not a core component;
types do not need to implement Arbitrary
unless one wants to use
any
or other free functions in this module.
Arbitrary
currently only works for types which represent owned data as
opposed to borrowed data. This is a fundamental restriction of proptest
which may be lifted in the future as the generic associated types (GAT)
feature of Rust is implemented and stabilized.
Required Associated Types§
sourcetype Parameters: Default
type Parameters: Default
The type of parameters that arbitrary_with
accepts for configuration
of the generated Strategy
. Parameters must implement Default
.
Required Methods§
sourcefn arbitrary_with(args: Self::Parameters) -> Self::Strategy
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
Provided Methods§
sourcefn arbitrary() -> Self::Strategy
fn arbitrary() -> Self::Strategy
Generates a Strategy
for producing arbitrary values
of type the implementing type (Self
).
Calling this for the type X
is the equivalent of using
X::arbitrary_with(Default::default())
.
This method is defined in the trait for optimization for the default if you want to do that. It is a logic error to not preserve the semantics when overriding.
Implementations on Foreign Types§
source§impl Arbitrary for IntoStringError
impl Arbitrary for IntoStringError
type Parameters = ()
type Strategy = Map<BoxedStrategy<Vec<u8, Global>>, fn(_: <BoxedStrategy<Vec<u8, Global>> as Strategy>::Value) -> IntoStringError>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl<T: Arbitrary> Arbitrary for SendError<T>
impl<T: Arbitrary> Arbitrary for SendError<T>
type Parameters = <T as Arbitrary>::Parameters
type Strategy = Map<<T as Arbitrary>::Strategy, fn(_: T) -> SendError<T>>
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for u16
impl Arbitrary for u16
type Parameters = ()
type Strategy = Any
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl<A: PartialOrd + Arbitrary> Arbitrary for RangeInclusive<A>
impl<A: PartialOrd + Arbitrary> Arbitrary for RangeInclusive<A>
type Parameters = (<A as Arbitrary>::Parameters, <A as Arbitrary>::Parameters)
type Strategy = Map<<(A, A) as Arbitrary>::Strategy, fn(_: (A, A)) -> RangeInclusive<A>>
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
source§impl<A: Arbitrary> Arbitrary for Option<A>
impl<A: Arbitrary> Arbitrary for Option<A>
type Parameters = (Probability, <A as Arbitrary>::Parameters)
type Strategy = OptionStrategy<<A as Arbitrary>::Strategy>
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
source§impl<A: Arbitrary, B: Arbitrary> Arbitrary for Result<A, B>
impl<A: Arbitrary, B: Arbitrary> Arbitrary for Result<A, B>
type Parameters = (Probability, <A as Arbitrary>::Parameters, <B as Arbitrary>::Parameters)
type Strategy = MaybeOk<<A as Arbitrary>::Strategy, <B as Arbitrary>::Strategy>
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for Stderr
impl Arbitrary for Stderr
type Parameters = ()
type Strategy = LazyJust<Stderr, fn() -> Stderr>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl<A: Arbitrary> Arbitrary for Arc<[A]>
impl<A: Arbitrary> Arbitrary for Arc<[A]>
type Parameters = <Vec<A, Global> as Arbitrary>::Parameters
type Strategy = MapInto<<Vec<A, Global> as Arbitrary>::Strategy, Arc<[A]>>
fn arbitrary_with(a: Self::Parameters) -> Self::Strategy
source§impl<A: Arbitrary> Arbitrary for Arc<A>
impl<A: Arbitrary> Arbitrary for Arc<A>
type Parameters = <A as Arbitrary>::Parameters
type Strategy = MapInto<<A as Arbitrary>::Strategy, Arc<A>>
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
source§impl<A: Arbitrary + DoubleEndedIterator> Arbitrary for Rev<A>
impl<A: Arbitrary + DoubleEndedIterator> Arbitrary for Rev<A>
type Parameters = <A as Arbitrary>::Parameters
type Strategy = Map<<A as Arbitrary>::Strategy, fn(_: A) -> Rev<A>>
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for NonZeroU32
impl Arbitrary for NonZeroU32
type Parameters = ()
type Strategy = FilterMap<<u32 as Arbitrary>::Strategy, fn(_: u32) -> Option<NonZeroU32>>
fn arbitrary_with((): Self::Parameters) -> Self::Strategy
source§impl Arbitrary for Args
impl Arbitrary for Args
type Parameters = ()
type Strategy = LazyJust<Args, fn() -> Args>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl<A: Arbitrary> Arbitrary for Discriminant<A>
impl<A: Arbitrary> Arbitrary for Discriminant<A>
type Parameters = <A as Arbitrary>::Parameters
type Strategy = Map<<A as Arbitrary>::Strategy, fn(_: A) -> Discriminant<A>>
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
source§impl<A: Arbitrary> Arbitrary for Once<A>
impl<A: Arbitrary> Arbitrary for Once<A>
type Parameters = <A as Arbitrary>::Parameters
type Strategy = Map<<A as Arbitrary>::Strategy, fn(_: A) -> Once<A>>
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
source§impl<A: Arbitrary + Ord, B: Arbitrary> Arbitrary for BTreeMap<A, B>
impl<A: Arbitrary + Ord, B: Arbitrary> Arbitrary for BTreeMap<A, B>
type Parameters = (SizeRange, <A as Arbitrary>::Parameters, <B as Arbitrary>::Parameters)
type Strategy = BTreeMapStrategy<<A as Arbitrary>::Strategy, <B as Arbitrary>::Strategy>
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
source§impl<A: Arbitrary + Read> Arbitrary for BufReader<A>
impl<A: Arbitrary + Read> Arbitrary for BufReader<A>
type Parameters = <A as Arbitrary>::Parameters
type Strategy = Map<<(A, Option<u16>) as Arbitrary>::Strategy, fn(_: (A, Option<u16>)) -> BufReader<A>>
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for ErrorKind
impl Arbitrary for ErrorKind
type Parameters = ()
type Strategy = Union<Just<ErrorKind>>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for Stdout
impl Arbitrary for Stdout
type Parameters = ()
type Strategy = LazyJust<Stdout, fn() -> Stdout>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for Sink
impl Arbitrary for Sink
type Parameters = ()
type Strategy = LazyJust<Sink, fn() -> Sink>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for RandomState
impl Arbitrary for RandomState
type Parameters = ()
type Strategy = LazyJust<RandomState, fn() -> RandomState>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for String
impl Arbitrary for String
source§fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
Panics
This implementation panics if the input is not a valid regex proptest can handle.