pub trait Arbitrary: Sized + Debug {
    type Parameters: Default;
    type Strategy: Strategy<Value = Self>;

    fn arbitrary_with(args: Self::Parameters) -> Self::Strategy;

    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 Strategys 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

The type of parameters that arbitrary_with accepts for configuration of the generated Strategy. Parameters must implement Default.

The type of Strategy used to generate values of type Self.

Required Methods

Generates a Strategy for producing arbitrary values of type the implementing type (Self). The strategy is passed the arguments given in args.

If you wish to use the default() arguments, use arbitrary instead.

Provided Methods

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


This implementation panics if the input is not a valid regex proptest can handle.