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.
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 Box<Path>
impl Arbitrary for Box<Path>
This implementation is identical to the Arbitrary
implementation for
PathBuf
.
type Parameters = PathParams
type Strategy = MapInto<<PathBuf as Arbitrary>::Strategy, Box<Path>>
fn arbitrary_with(args: 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 Rc<Path>
impl Arbitrary for Rc<Path>
This implementation is identical to the Arbitrary
implementation for
PathBuf
.
type Parameters = PathParams
type Strategy = MapInto<<PathBuf as Arbitrary>::Strategy, Rc<Path>>
fn arbitrary_with(args: 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.
type Parameters = StringParam
type Strategy = &'static str
source§impl Arbitrary for Arc<str>
impl Arbitrary for Arc<str>
type Parameters = StringParam
type Strategy = MapInto<<String as Arbitrary>::Strategy, Arc<str>>
fn arbitrary_with(a: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for Arc<Path>
impl Arbitrary for Arc<Path>
This implementation is identical to the Arbitrary
implementation for
PathBuf
.
type Parameters = PathParams
type Strategy = MapInto<<PathBuf as Arbitrary>::Strategy, Arc<Path>>
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for EscapeDefault
impl Arbitrary for EscapeDefault
type Parameters = ()
type Strategy = Map<<u8 as Arbitrary>::Strategy, fn(_: u8) -> EscapeDefault>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for BorrowError
impl Arbitrary for BorrowError
type Parameters = ()
type Strategy = LazyJust<BorrowError, fn() -> BorrowError>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for BorrowMutError
impl Arbitrary for BorrowMutError
type Parameters = ()
type Strategy = LazyJust<BorrowMutError, fn() -> BorrowMutError>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for ParseCharError
impl Arbitrary for ParseCharError
type Parameters = ()
type Strategy = IndFlatten<Map<<bool as Arbitrary>::Strategy, fn(_: bool) -> Just<ParseCharError>>>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter>
impl Arbitrary for DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter>
type Parameters = ()
type Strategy = Map<<Vec<u16> as Arbitrary>::Strategy, fn(_: Vec<u16>) -> DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter>>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for DecodeUtf16Error
impl Arbitrary for DecodeUtf16Error
source§impl Arbitrary for EscapeDebug
impl Arbitrary for EscapeDebug
type Parameters = ()
type Strategy = Map<<char as Arbitrary>::Strategy, fn(_: char) -> EscapeDebug>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for EscapeDefault
impl Arbitrary for EscapeDefault
type Parameters = ()
type Strategy = Map<<char as Arbitrary>::Strategy, fn(_: char) -> EscapeDefault>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for EscapeUnicode
impl Arbitrary for EscapeUnicode
type Parameters = ()
type Strategy = Map<<char as Arbitrary>::Strategy, fn(_: char) -> EscapeUnicode>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for FromBytesWithNulError
impl Arbitrary for FromBytesWithNulError
source§impl Arbitrary for Error
impl Arbitrary for Error
type Parameters = ()
type Strategy = Just<Error>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for AddrParseError
impl Arbitrary for AddrParseError
type Parameters = ()
type Strategy = Just<AddrParseError>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
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>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for ParseIntError
impl Arbitrary for ParseIntError
type Parameters = ()
type Strategy = Just<ParseIntError>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for RangeFull
impl Arbitrary for RangeFull
type Parameters = ()
type Strategy = Just<RangeFull>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for ParseBoolError
impl Arbitrary for ParseBoolError
type Parameters = ()
type Strategy = Just<ParseBoolError>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
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>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for AtomicBool
impl Arbitrary for AtomicBool
type Parameters = ()
type Strategy = Map<<bool as Arbitrary>::Strategy, fn(_: bool) -> AtomicBool>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for AtomicIsize
impl Arbitrary for AtomicIsize
type Parameters = ()
type Strategy = Map<<isize as Arbitrary>::Strategy, fn(_: isize) -> AtomicIsize>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for AtomicUsize
impl Arbitrary for AtomicUsize
type Parameters = ()
type Strategy = Map<<usize as Arbitrary>::Strategy, fn(_: usize) -> AtomicUsize>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for JoinPathsError
impl Arbitrary for JoinPathsError
type Parameters = ()
type Strategy = LazyJust<JoinPathsError, fn() -> JoinPathsError>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for OsString
impl Arbitrary for OsString
type Parameters = <String as Arbitrary>::Parameters
type Strategy = MapInto<<String as Arbitrary>::Strategy, OsString>
fn arbitrary_with(a: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for DirBuilder
impl Arbitrary for DirBuilder
type Parameters = ()
type Strategy = Map<<bool as Arbitrary>::Strategy, fn(_: bool) -> DirBuilder>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
source§impl Arbitrary for DefaultHasher
impl Arbitrary for DefaultHasher
type Parameters = ()
type Strategy = LazyJust<DefaultHasher, fn() -> DefaultHasher>
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 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)