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.
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
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.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementations on Foreign Types§
Source§impl Arbitrary for char
impl Arbitrary for char
type Parameters = ()
type Strategy = CharStrategy<'static>
fn arbitrary_with( _args: <char as Arbitrary>::Parameters, ) -> <char as Arbitrary>::Strategy
Source§impl<A> Arbitrary for (SyncSender<A>, IntoIter<A>)where
A: Debug,
impl<A> Arbitrary for (SyncSender<A>, IntoIter<A>)where
A: Debug,
type Parameters = ()
type Strategy = Map<<u16 as Arbitrary>::Strategy, fn(_: u16) -> (SyncSender<A>, IntoIter<A>)>
fn arbitrary_with( _args: <(SyncSender<A>, IntoIter<A>) as Arbitrary>::Parameters, ) -> <(SyncSender<A>, IntoIter<A>) as Arbitrary>::Strategy
Source§impl<A> Arbitrary for (SyncSender<A>, Receiver<A>)
impl<A> Arbitrary for (SyncSender<A>, Receiver<A>)
type Parameters = ()
type Strategy = Map<<u16 as Arbitrary>::Strategy, fn(_: u16) -> (SyncSender<A>, Receiver<A>)>
fn arbitrary_with( _args: <(SyncSender<A>, Receiver<A>) as Arbitrary>::Parameters, ) -> <(SyncSender<A>, Receiver<A>) as Arbitrary>::Strategy
Source§impl<A, const N: usize> Arbitrary for [A; N]where
A: Arbitrary,
impl<A, const N: usize> Arbitrary for [A; N]where
A: Arbitrary,
type Parameters = <A as Arbitrary>::Parameters
type Strategy = UniformArrayStrategy<<A as Arbitrary>::Strategy, [A; N]>
fn arbitrary_with( args: <[A; N] as Arbitrary>::Parameters, ) -> <[A; N] as Arbitrary>::Strategy
Source§impl<T0> Arbitrary for (T0,)where
T0: Arbitrary,
impl<T0> Arbitrary for (T0,)where
T0: Arbitrary,
type Parameters = (<T0 as Arbitrary>::Parameters,)
type Strategy = (<T0 as Arbitrary>::Strategy,)
fn arbitrary_with( args: <(T0,) as Arbitrary>::Parameters, ) -> <(T0,) as Arbitrary>::Strategy
Source§impl<T0, T1> Arbitrary for (T0, T1)
impl<T0, T1> Arbitrary for (T0, T1)
type Parameters = (<T0 as Arbitrary>::Parameters, <T1 as Arbitrary>::Parameters)
type Strategy = (<T0 as Arbitrary>::Strategy, <T1 as Arbitrary>::Strategy)
fn arbitrary_with( args: <(T0, T1) as Arbitrary>::Parameters, ) -> <(T0, T1) as Arbitrary>::Strategy
Source§impl<T0, T1, T2> Arbitrary for (T0, T1, T2)
impl<T0, T1, T2> Arbitrary for (T0, T1, T2)
type Parameters = (<T0 as Arbitrary>::Parameters, <T1 as Arbitrary>::Parameters, <T2 as Arbitrary>::Parameters)
type Strategy = (<T0 as Arbitrary>::Strategy, <T1 as Arbitrary>::Strategy, <T2 as Arbitrary>::Strategy)
fn arbitrary_with( args: <(T0, T1, T2) as Arbitrary>::Parameters, ) -> <(T0, T1, T2) as Arbitrary>::Strategy
Source§impl<T0, T1, T2, T3> Arbitrary for (T0, T1, T2, T3)
impl<T0, T1, T2, T3> Arbitrary for (T0, T1, T2, T3)
type Parameters = (<T0 as Arbitrary>::Parameters, <T1 as Arbitrary>::Parameters, <T2 as Arbitrary>::Parameters, <T3 as Arbitrary>::Parameters)
type Strategy = (<T0 as Arbitrary>::Strategy, <T1 as Arbitrary>::Strategy, <T2 as Arbitrary>::Strategy, <T3 as Arbitrary>::Strategy)
fn arbitrary_with( args: <(T0, T1, T2, T3) as Arbitrary>::Parameters, ) -> <(T0, T1, T2, T3) as Arbitrary>::Strategy
Source§impl<T0, T1, T2, T3, T4> Arbitrary for (T0, T1, T2, T3, T4)
impl<T0, T1, T2, T3, T4> Arbitrary for (T0, T1, T2, T3, T4)
type Parameters = (<T0 as Arbitrary>::Parameters, <T1 as Arbitrary>::Parameters, <T2 as Arbitrary>::Parameters, <T3 as Arbitrary>::Parameters, <T4 as Arbitrary>::Parameters)
type Strategy = (<T0 as Arbitrary>::Strategy, <T1 as Arbitrary>::Strategy, <T2 as Arbitrary>::Strategy, <T3 as Arbitrary>::Strategy, <T4 as Arbitrary>::Strategy)
fn arbitrary_with( args: <(T0, T1, T2, T3, T4) as Arbitrary>::Parameters, ) -> <(T0, T1, T2, T3, T4) as Arbitrary>::Strategy
Source§impl<T0, T1, T2, T3, T4, T5> Arbitrary for (T0, T1, T2, T3, T4, T5)
impl<T0, T1, T2, T3, T4, T5> Arbitrary for (T0, T1, T2, T3, T4, T5)
type Parameters = (<T0 as Arbitrary>::Parameters, <T1 as Arbitrary>::Parameters, <T2 as Arbitrary>::Parameters, <T3 as Arbitrary>::Parameters, <T4 as Arbitrary>::Parameters, <T5 as Arbitrary>::Parameters)
type Strategy = (<T0 as Arbitrary>::Strategy, <T1 as Arbitrary>::Strategy, <T2 as Arbitrary>::Strategy, <T3 as Arbitrary>::Strategy, <T4 as Arbitrary>::Strategy, <T5 as Arbitrary>::Strategy)
fn arbitrary_with( args: <(T0, T1, T2, T3, T4, T5) as Arbitrary>::Parameters, ) -> <(T0, T1, T2, T3, T4, T5) as Arbitrary>::Strategy
Source§impl<T0, T1, T2, T3, T4, T5, T6> Arbitrary for (T0, T1, T2, T3, T4, T5, T6)
impl<T0, T1, T2, T3, T4, T5, T6> Arbitrary for (T0, T1, T2, T3, T4, T5, T6)
type Parameters = (<T0 as Arbitrary>::Parameters, <T1 as Arbitrary>::Parameters, <T2 as Arbitrary>::Parameters, <T3 as Arbitrary>::Parameters, <T4 as Arbitrary>::Parameters, <T5 as Arbitrary>::Parameters, <T6 as Arbitrary>::Parameters)
type Strategy = (<T0 as Arbitrary>::Strategy, <T1 as Arbitrary>::Strategy, <T2 as Arbitrary>::Strategy, <T3 as Arbitrary>::Strategy, <T4 as Arbitrary>::Strategy, <T5 as Arbitrary>::Strategy, <T6 as Arbitrary>::Strategy)
fn arbitrary_with( args: <(T0, T1, T2, T3, T4, T5, T6) as Arbitrary>::Parameters, ) -> <(T0, T1, T2, T3, T4, T5, T6) as Arbitrary>::Strategy
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7> Arbitrary for (T0, T1, T2, T3, T4, T5, T6, T7)
impl<T0, T1, T2, T3, T4, T5, T6, T7> Arbitrary for (T0, T1, T2, T3, T4, T5, T6, T7)
type Parameters = (<T0 as Arbitrary>::Parameters, <T1 as Arbitrary>::Parameters, <T2 as Arbitrary>::Parameters, <T3 as Arbitrary>::Parameters, <T4 as Arbitrary>::Parameters, <T5 as Arbitrary>::Parameters, <T6 as Arbitrary>::Parameters, <T7 as Arbitrary>::Parameters)
type Strategy = (<T0 as Arbitrary>::Strategy, <T1 as Arbitrary>::Strategy, <T2 as Arbitrary>::Strategy, <T3 as Arbitrary>::Strategy, <T4 as Arbitrary>::Strategy, <T5 as Arbitrary>::Strategy, <T6 as Arbitrary>::Strategy, <T7 as Arbitrary>::Strategy)
fn arbitrary_with( args: <(T0, T1, T2, T3, T4, T5, T6, T7) as Arbitrary>::Parameters, ) -> <(T0, T1, T2, T3, T4, T5, T6, T7) as Arbitrary>::Strategy
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8> Arbitrary for (T0, T1, T2, T3, T4, T5, T6, T7, T8)
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8> Arbitrary for (T0, T1, T2, T3, T4, T5, T6, T7, T8)
type Parameters = (<T0 as Arbitrary>::Parameters, <T1 as Arbitrary>::Parameters, <T2 as Arbitrary>::Parameters, <T3 as Arbitrary>::Parameters, <T4 as Arbitrary>::Parameters, <T5 as Arbitrary>::Parameters, <T6 as Arbitrary>::Parameters, <T7 as Arbitrary>::Parameters, <T8 as Arbitrary>::Parameters)
type Strategy = (<T0 as Arbitrary>::Strategy, <T1 as Arbitrary>::Strategy, <T2 as Arbitrary>::Strategy, <T3 as Arbitrary>::Strategy, <T4 as Arbitrary>::Strategy, <T5 as Arbitrary>::Strategy, <T6 as Arbitrary>::Strategy, <T7 as Arbitrary>::Strategy, <T8 as Arbitrary>::Strategy)
fn arbitrary_with( args: <(T0, T1, T2, T3, T4, T5, T6, T7, T8) as Arbitrary>::Parameters, ) -> <(T0, T1, T2, T3, T4, T5, T6, T7, T8) as Arbitrary>::Strategy
Source§impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> Arbitrary for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)
impl<T0, T1, T2, T3, T4, T5, T6, T7, T8, T9> Arbitrary for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)
type Parameters = (<T0 as Arbitrary>::Parameters, <T1 as Arbitrary>::Parameters, <T2 as Arbitrary>::Parameters, <T3 as Arbitrary>::Parameters, <T4 as Arbitrary>::Parameters, <T5 as Arbitrary>::Parameters, <T6 as Arbitrary>::Parameters, <T7 as Arbitrary>::Parameters, <T8 as Arbitrary>::Parameters, <T9 as Arbitrary>::Parameters)
type Strategy = (<T0 as Arbitrary>::Strategy, <T1 as Arbitrary>::Strategy, <T2 as Arbitrary>::Strategy, <T3 as Arbitrary>::Strategy, <T4 as Arbitrary>::Strategy, <T5 as Arbitrary>::Strategy, <T6 as Arbitrary>::Strategy, <T7 as Arbitrary>::Strategy, <T8 as Arbitrary>::Strategy, <T9 as Arbitrary>::Strategy)
fn arbitrary_with( args: <(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) as Arbitrary>::Parameters, ) -> <(T0, T1, T2, T3, T4, T5, T6, T7, T8, T9) as Arbitrary>::Strategy
Implementors§
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>>))>
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>>))>
Source§impl Arbitrary for Option<Infallible>
impl Arbitrary for Option<Infallible>
type Parameters = ()
type Strategy = Just<Option<Infallible>>
Source§impl Arbitrary for RecvTimeoutError
impl Arbitrary for RecvTimeoutError
type Parameters = ()
type Strategy = TupleUnion<((u32, Arc<Just<RecvTimeoutError>>), (u32, Arc<Just<RecvTimeoutError>>))>
Source§impl Arbitrary for TryRecvError
impl Arbitrary for TryRecvError
type Parameters = ()
type Strategy = TupleUnion<((u32, Arc<Just<TryRecvError>>), (u32, Arc<Just<TryRecvError>>))>
Source§impl Arbitrary for rustmax::std::ascii::EscapeDefault
impl Arbitrary for rustmax::std::ascii::EscapeDefault
Source§impl Arbitrary for Box<Path>
impl Arbitrary for Box<Path>
This implementation is identical to the Arbitrary
implementation for
PathBuf
.
Source§impl Arbitrary for BorrowError
impl Arbitrary for BorrowError
type Parameters = ()
type Strategy = LazyJust<BorrowError, fn() -> BorrowError>
Source§impl Arbitrary for BorrowMutError
impl Arbitrary for BorrowMutError
type Parameters = ()
type Strategy = LazyJust<BorrowMutError, fn() -> BorrowMutError>
Source§impl Arbitrary for DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter>
impl Arbitrary for DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter>
Source§impl Arbitrary for DecodeUtf16Error
impl Arbitrary for DecodeUtf16Error
Source§impl Arbitrary for EscapeDebug
impl Arbitrary for EscapeDebug
Source§impl Arbitrary for rustmax::std::char::EscapeDefault
impl Arbitrary for rustmax::std::char::EscapeDefault
Source§impl Arbitrary for EscapeUnicode
impl Arbitrary for EscapeUnicode
Source§impl Arbitrary for ParseCharError
impl Arbitrary for ParseCharError
Source§impl Arbitrary for JoinPathsError
impl Arbitrary for JoinPathsError
type Parameters = ()
type Strategy = LazyJust<JoinPathsError, fn() -> JoinPathsError>
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>
Source§impl Arbitrary for FromBytesWithNulError
impl Arbitrary for FromBytesWithNulError
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>
Source§impl Arbitrary for DirBuilder
impl Arbitrary for DirBuilder
Source§impl Arbitrary for DefaultHasher
impl Arbitrary for DefaultHasher
type Parameters = ()
type Strategy = LazyJust<DefaultHasher, fn() -> DefaultHasher>
Source§impl Arbitrary for RandomState
impl Arbitrary for RandomState
type Parameters = ()
type Strategy = LazyJust<RandomState, fn() -> RandomState>
Source§impl Arbitrary for AddrParseError
impl Arbitrary for AddrParseError
type Parameters = ()
type Strategy = Just<AddrParseError>
Source§impl Arbitrary for SocketAddrV4
impl Arbitrary for SocketAddrV4
Source§impl Arbitrary for SocketAddrV6
impl Arbitrary for SocketAddrV6
Source§impl Arbitrary for ParseFloatError
impl Arbitrary for ParseFloatError
type Parameters = ()
type Strategy = Just<ParseFloatError>
Source§impl Arbitrary for ParseIntError
impl Arbitrary for ParseIntError
type Parameters = ()
type Strategy = Just<ParseIntError>
Source§impl Arbitrary for PathBuf
impl Arbitrary for PathBuf
This implementation accepts as its argument a PathParams
struct. It generates either a
relative or an absolute path with equal probability.
Currently, this implementation does not generate:
- Paths that are not valid UTF-8 (this is unlikely to change)
- Paths with a
PrefixComponent
on Windows, e.g.C:\
(this may change in the future)
Source§impl Arbitrary for StripPrefixError
impl Arbitrary for StripPrefixError
type Parameters = ()
type Strategy = Just<StripPrefixError>
Source§impl Arbitrary for Rc<Path>
impl Arbitrary for Rc<Path>
This implementation is identical to the Arbitrary
implementation for
PathBuf
.
Source§impl Arbitrary for ParseBoolError
impl Arbitrary for ParseBoolError
type Parameters = ()
type Strategy = Just<ParseBoolError>
Source§impl Arbitrary for Utf8Error
impl Arbitrary for Utf8Error
type Parameters = ()
type Strategy = Map<(<u16 as Arbitrary>::Strategy, TupleUnion<((u32, Arc<Just<&'static [u8]>>), (u32, Arc<Just<&'static [u8]>>), (u32, Arc<Just<&'static [u8]>>), (u32, Arc<Just<&'static [u8]>>))>), fn(_: <(<u16 as Arbitrary>::Strategy, TupleUnion<((u32, Arc<Just<&'static [u8]>>), (u32, Arc<Just<&'static [u8]>>), (u32, Arc<Just<&'static [u8]>>), (u32, Arc<Just<&'static [u8]>>))>) as Strategy>::Value) -> Utf8Error>
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>
Source§impl Arbitrary for FromUtf16Error
impl Arbitrary for FromUtf16Error
type Parameters = ()
type Strategy = LazyJust<FromUtf16Error, fn() -> FromUtf16Error>
Source§impl Arbitrary for String
impl Arbitrary for String
type Parameters = StringParam
type Strategy = &'static str
Source§impl Arbitrary for AtomicBool
impl Arbitrary for AtomicBool
Source§impl Arbitrary for AtomicIsize
impl Arbitrary for AtomicIsize
Source§impl Arbitrary for AtomicUsize
impl Arbitrary for AtomicUsize
Source§impl Arbitrary for Arc<Path>
impl Arbitrary for Arc<Path>
This implementation is identical to the Arbitrary
implementation for
PathBuf
.