Trait Arbitrary

trait Arbitrary: Sized + fmt::Debug

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.

If you do not have unique constraints on how to generate the data for your custom types, consider using the derive macro to implement Arbitrary

Associated Types

type Parameters: TraitBound { trait_: Path { path: "Default", id: Id(34), args: None }, generic_params: [], modifier: None }

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

type Strategy: TraitBound { trait_: Path { path: "Strategy", id: Id(39), args: Some(AngleBracketed { args: [], constraints: [AssocItemConstraint { name: "Value", args: None, binding: Equality(Type(Generic("Self"))) }] }) }, generic_params: [], modifier: None }

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

Required Methods

fn arbitrary_with(args: <Self as >::Parameters) -> <Self as >::Strategy

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

fn arbitrary() -> <Self as >::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.

Implementors