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.
Object Safety§
Implementations on Foreign Types§
source§impl Arbitrary for SocketAddr
impl Arbitrary for SocketAddr
type Parameters = ()
type Strategy = TupleUnion<((u32, Arc<MapInto<<SocketAddrV4 as Arbitrary>::Strategy, SocketAddr>>), (u32, Arc<MapInto<<SocketAddrV6 as Arbitrary>::Strategy, SocketAddr>>))>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for FpCategory
impl Arbitrary for FpCategory
type Parameters = ()
type Strategy = TupleUnion<((u32, Arc<Just<FpCategory>>), (u32, Arc<Just<FpCategory>>), (u32, Arc<Just<FpCategory>>), (u32, Arc<Just<FpCategory>>), (u32, Arc<Just<FpCategory>>))>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for Option<ParseError>
impl Arbitrary for Option<ParseError>
type Parameters = ()
type Strategy = Just<Option<Infallible>>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for VarError
impl Arbitrary for VarError
type Parameters = ()
type Strategy = TupleUnion<((u32, Arc<Just<VarError>>), (u32, Arc<Map<BoxedStrategy<OsString>, fn(_: <BoxedStrategy<OsString> as Strategy>::Value) -> VarError>>))>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for SeekFrom
impl Arbitrary for SeekFrom
type Parameters = ()
type Strategy = TupleUnion<((u32, Arc<Map<<u64 as Arbitrary>::Strategy, fn(_: u64) -> SeekFrom>>), (u32, Arc<Map<<i64 as Arbitrary>::Strategy, fn(_: i64) -> SeekFrom>>), (u32, Arc<Map<<i64 as Arbitrary>::Strategy, fn(_: i64) -> SeekFrom>>))>
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 RecvTimeoutError
impl Arbitrary for RecvTimeoutError
type Parameters = ()
type Strategy = TupleUnion<((u32, Arc<Just<RecvTimeoutError>>), (u32, Arc<Just<RecvTimeoutError>>))>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for TryRecvError
impl Arbitrary for TryRecvError
type Parameters = ()
type Strategy = TupleUnion<((u32, Arc<Just<TryRecvError>>), (u32, Arc<Just<TryRecvError>>))>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for bool
impl Arbitrary for bool
type Parameters = ()
type Strategy = Any
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for char
impl Arbitrary for char
type Parameters = ()
type Strategy = CharStrategy<'static>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for f32
impl Arbitrary for f32
type Parameters = ()
type Strategy = Any
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for f64
impl Arbitrary for f64
type Parameters = ()
type Strategy = Any
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for i8
impl Arbitrary for i8
type Parameters = ()
type Strategy = Any
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for i16
impl Arbitrary for i16
type Parameters = ()
type Strategy = Any
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for i32
impl Arbitrary for i32
type Parameters = ()
type Strategy = Any
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for i64
impl Arbitrary for i64
type Parameters = ()
type Strategy = Any
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for i128
impl Arbitrary for i128
type Parameters = ()
type Strategy = Any
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for isize
impl Arbitrary for isize
type Parameters = ()
type Strategy = Any
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for u8
impl Arbitrary for u8
type Parameters = ()
type Strategy = Any
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 Arbitrary for u32
impl Arbitrary for u32
type Parameters = ()
type Strategy = Any
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for u64
impl Arbitrary for u64
type Parameters = ()
type Strategy = Any
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for u128
impl Arbitrary for u128
type Parameters = ()
type Strategy = Any
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for ()
impl Arbitrary for ()
type Parameters = ()
type Strategy = Just<()>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for usize
impl Arbitrary for usize
type Parameters = ()
type Strategy = Any
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for Box<str>
impl Arbitrary for Box<str>
type Parameters = StringParam
type Strategy = MapInto<<String as Arbitrary>::Strategy, Box<str>>
fn arbitrary_with(a: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for Box<OsStr>
impl Arbitrary for Box<OsStr>
type Parameters = <String as Arbitrary>::Parameters
type Strategy = MapInto<<OsString as Arbitrary>::Strategy, Box<OsStr>>
fn arbitrary_with(a: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for CString
impl Arbitrary for CString
type Parameters = SizeRange
type Strategy = Map<VecStrategy<RangeInclusive<u8>>, fn(_: <VecStrategy<RangeInclusive<u8>> as Strategy>::Value) -> CString>
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for IntoStringError
impl Arbitrary for IntoStringError
type Parameters = ()
type Strategy = Map<BoxedStrategy<Vec<u8>>, fn(_: <BoxedStrategy<Vec<u8>> as Strategy>::Value) -> IntoStringError>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for Rc<str>
impl Arbitrary for Rc<str>
type Parameters = StringParam
type Strategy = MapInto<<String as Arbitrary>::Strategy, Rc<str>>
fn arbitrary_with(a: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for FromUtf8Error
impl Arbitrary for FromUtf8Error
type Parameters = ()
type Strategy = Map<BoxedStrategy<Vec<u8>>, fn(_: <BoxedStrategy<Vec<u8>> as Strategy>::Value) -> FromUtf8Error>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for FromUtf16Error
impl Arbitrary for FromUtf16Error
type Parameters = ()
type Strategy = LazyJust<FromUtf16Error, fn() -> FromUtf16Error>
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.