Trait zebra_test::prelude::Arbitrary
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§
type 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§
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
Provided Methods§
fn 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§
§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: <SocketAddr as Arbitrary>::Parameters, ) -> <SocketAddr as Arbitrary>::Strategy
§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: <FpCategory as Arbitrary>::Parameters, ) -> <FpCategory as Arbitrary>::Strategy
§impl Arbitrary for Option<Infallible>
impl Arbitrary for Option<Infallible>
type Parameters = ()
type Strategy = Just<Option<Infallible>>
fn arbitrary_with( _args: <Option<Infallible> as Arbitrary>::Parameters, ) -> <Option<Infallible> as Arbitrary>::Strategy
§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: <VarError as Arbitrary>::Parameters, ) -> <VarError as Arbitrary>::Strategy
§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: <SeekFrom as Arbitrary>::Parameters, ) -> <SeekFrom as Arbitrary>::Strategy
§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: <RecvTimeoutError as Arbitrary>::Parameters, ) -> <RecvTimeoutError as Arbitrary>::Strategy
§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: <TryRecvError as Arbitrary>::Parameters, ) -> <TryRecvError as Arbitrary>::Strategy
§impl Arbitrary for bool
impl Arbitrary for bool
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <bool as Arbitrary>::Parameters, ) -> <bool as Arbitrary>::Strategy
§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
§impl Arbitrary for f32
impl Arbitrary for f32
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <f32 as Arbitrary>::Parameters, ) -> <f32 as Arbitrary>::Strategy
§impl Arbitrary for f64
impl Arbitrary for f64
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <f64 as Arbitrary>::Parameters, ) -> <f64 as Arbitrary>::Strategy
§impl Arbitrary for i8
impl Arbitrary for i8
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <i8 as Arbitrary>::Parameters, ) -> <i8 as Arbitrary>::Strategy
§impl Arbitrary for i16
impl Arbitrary for i16
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <i16 as Arbitrary>::Parameters, ) -> <i16 as Arbitrary>::Strategy
§impl Arbitrary for i32
impl Arbitrary for i32
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <i32 as Arbitrary>::Parameters, ) -> <i32 as Arbitrary>::Strategy
§impl Arbitrary for i64
impl Arbitrary for i64
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <i64 as Arbitrary>::Parameters, ) -> <i64 as Arbitrary>::Strategy
§impl Arbitrary for i128
impl Arbitrary for i128
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <i128 as Arbitrary>::Parameters, ) -> <i128 as Arbitrary>::Strategy
§impl Arbitrary for isize
impl Arbitrary for isize
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <isize as Arbitrary>::Parameters, ) -> <isize as Arbitrary>::Strategy
§impl Arbitrary for u8
impl Arbitrary for u8
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <u8 as Arbitrary>::Parameters, ) -> <u8 as Arbitrary>::Strategy
§impl Arbitrary for u16
impl Arbitrary for u16
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <u16 as Arbitrary>::Parameters, ) -> <u16 as Arbitrary>::Strategy
§impl Arbitrary for u32
impl Arbitrary for u32
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <u32 as Arbitrary>::Parameters, ) -> <u32 as Arbitrary>::Strategy
§impl Arbitrary for u64
impl Arbitrary for u64
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <u64 as Arbitrary>::Parameters, ) -> <u64 as Arbitrary>::Strategy
§impl Arbitrary for u128
impl Arbitrary for u128
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <u128 as Arbitrary>::Parameters, ) -> <u128 as Arbitrary>::Strategy
§impl Arbitrary for ()
impl Arbitrary for ()
type Parameters = ()
type Strategy = Just<()>
fn arbitrary_with( _args: <() as Arbitrary>::Parameters, ) -> <() as Arbitrary>::Strategy
§impl Arbitrary for usize
impl Arbitrary for usize
type Parameters = ()
type Strategy = Any
fn arbitrary_with( _args: <usize as Arbitrary>::Parameters, ) -> <usize as Arbitrary>::Strategy
§impl Arbitrary for Box<Path>
impl Arbitrary for Box<Path>
This implementation is identical to the Arbitrary
implementation for
PathBuf
.
§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: <CString as Arbitrary>::Parameters, ) -> <CString as Arbitrary>::Strategy
§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: <IntoStringError as Arbitrary>::Parameters, ) -> <IntoStringError as Arbitrary>::Strategy
§impl Arbitrary for Rc<Path>
impl Arbitrary for Rc<Path>
This implementation is identical to the Arbitrary
implementation for
PathBuf
.
§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: <FromUtf8Error as Arbitrary>::Parameters, ) -> <FromUtf8Error as Arbitrary>::Strategy
§impl Arbitrary for FromUtf16Error
impl Arbitrary for FromUtf16Error
type Parameters = ()
type Strategy = LazyJust<FromUtf16Error, fn() -> FromUtf16Error>
fn arbitrary_with( _args: <FromUtf16Error as Arbitrary>::Parameters, ) -> <FromUtf16Error as Arbitrary>::Strategy
§impl Arbitrary for String
impl Arbitrary for String
§fn arbitrary_with(
args: <String as Arbitrary>::Parameters,
) -> <String as Arbitrary>::Strategy
fn arbitrary_with( args: <String as Arbitrary>::Parameters, ) -> <String as Arbitrary>::Strategy
§Panics
This implementation panics if the input is not a valid regex proptest can handle.
type Parameters = StringParam
type Strategy = &'static str
§impl Arbitrary for Arc<Path>
impl Arbitrary for Arc<Path>
This implementation is identical to the Arbitrary
implementation for
PathBuf
.
§impl Arbitrary for EscapeDefault
impl Arbitrary for EscapeDefault
type Parameters = ()
type Strategy = Map<<u8 as Arbitrary>::Strategy, fn(_: u8) -> EscapeDefault>
fn arbitrary_with( _args: <EscapeDefault as Arbitrary>::Parameters, ) -> <EscapeDefault as Arbitrary>::Strategy
§impl Arbitrary for BorrowError
impl Arbitrary for BorrowError
type Parameters = ()
type Strategy = LazyJust<BorrowError, fn() -> BorrowError>
fn arbitrary_with( _args: <BorrowError as Arbitrary>::Parameters, ) -> <BorrowError as Arbitrary>::Strategy
§impl Arbitrary for BorrowMutError
impl Arbitrary for BorrowMutError
type Parameters = ()
type Strategy = LazyJust<BorrowMutError, fn() -> BorrowMutError>
fn arbitrary_with( _args: <BorrowMutError as Arbitrary>::Parameters, ) -> <BorrowMutError as Arbitrary>::Strategy
§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: <ParseCharError as Arbitrary>::Parameters, ) -> <ParseCharError as Arbitrary>::Strategy
§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: <DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter> as Arbitrary>::Parameters, ) -> <DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter> as Arbitrary>::Strategy
§impl Arbitrary for DecodeUtf16Error
impl Arbitrary for DecodeUtf16Error
type Parameters = ()
type Strategy = Map<Range<u16>, fn(_: <Range<u16> as Strategy>::Value) -> DecodeUtf16Error>
fn arbitrary_with( _args: <DecodeUtf16Error as Arbitrary>::Parameters, ) -> <DecodeUtf16Error as Arbitrary>::Strategy
§impl Arbitrary for EscapeDebug
impl Arbitrary for EscapeDebug
type Parameters = ()
type Strategy = Map<<char as Arbitrary>::Strategy, fn(_: char) -> EscapeDebug>
fn arbitrary_with( _args: <EscapeDebug as Arbitrary>::Parameters, ) -> <EscapeDebug as Arbitrary>::Strategy
§impl Arbitrary for EscapeDefault
impl Arbitrary for EscapeDefault
type Parameters = ()
type Strategy = Map<<char as Arbitrary>::Strategy, fn(_: char) -> EscapeDefault>
fn arbitrary_with( _args: <EscapeDefault as Arbitrary>::Parameters, ) -> <EscapeDefault as Arbitrary>::Strategy
§impl Arbitrary for EscapeUnicode
impl Arbitrary for EscapeUnicode
type Parameters = ()
type Strategy = Map<<char as Arbitrary>::Strategy, fn(_: char) -> EscapeUnicode>
fn arbitrary_with( _args: <EscapeUnicode as Arbitrary>::Parameters, ) -> <EscapeUnicode as Arbitrary>::Strategy
§impl Arbitrary for FromBytesWithNulError
impl Arbitrary for FromBytesWithNulError
type Parameters = ()
type Strategy = Map<<Option<u16> as Arbitrary>::Strategy, fn(_: Option<u16>) -> FromBytesWithNulError>
fn arbitrary_with( _args: <FromBytesWithNulError as Arbitrary>::Parameters, ) -> <FromBytesWithNulError as Arbitrary>::Strategy
§impl Arbitrary for Error
impl Arbitrary for Error
type Parameters = ()
type Strategy = Just<Error>
fn arbitrary_with( _args: <Error as Arbitrary>::Parameters, ) -> <Error as Arbitrary>::Strategy
§impl Arbitrary for AddrParseError
impl Arbitrary for AddrParseError
type Parameters = ()
type Strategy = Just<AddrParseError>
fn arbitrary_with( _args: <AddrParseError as Arbitrary>::Parameters, ) -> <AddrParseError as Arbitrary>::Strategy
§impl Arbitrary for SocketAddrV4
impl Arbitrary for SocketAddrV4
type Parameters = ()
type Strategy = Map<<(Ipv4Addr, u16) as Arbitrary>::Strategy, fn(_: (Ipv4Addr, u16)) -> SocketAddrV4>
fn arbitrary_with( _args: <SocketAddrV4 as Arbitrary>::Parameters, ) -> <SocketAddrV4 as Arbitrary>::Strategy
§impl Arbitrary for SocketAddrV6
impl Arbitrary for SocketAddrV6
type Parameters = ()
type Strategy = Map<<(Ipv6Addr, u16, u32, u32) as Arbitrary>::Strategy, fn(_: (Ipv6Addr, u16, u32, u32)) -> SocketAddrV6>
fn arbitrary_with( _args: <SocketAddrV6 as Arbitrary>::Parameters, ) -> <SocketAddrV6 as Arbitrary>::Strategy
§impl Arbitrary for ParseFloatError
impl Arbitrary for ParseFloatError
type Parameters = ()
type Strategy = Just<ParseFloatError>
fn arbitrary_with( _args: <ParseFloatError as Arbitrary>::Parameters, ) -> <ParseFloatError as Arbitrary>::Strategy
§impl Arbitrary for ParseIntError
impl Arbitrary for ParseIntError
type Parameters = ()
type Strategy = Just<ParseIntError>
fn arbitrary_with( _args: <ParseIntError as Arbitrary>::Parameters, ) -> <ParseIntError as Arbitrary>::Strategy
§impl Arbitrary for RangeFull
impl Arbitrary for RangeFull
type Parameters = ()
type Strategy = Just<RangeFull>
fn arbitrary_with( _args: <RangeFull as Arbitrary>::Parameters, ) -> <RangeFull as Arbitrary>::Strategy
§impl Arbitrary for ParseBoolError
impl Arbitrary for ParseBoolError
type Parameters = ()
type Strategy = Just<ParseBoolError>
fn arbitrary_with( _args: <ParseBoolError as Arbitrary>::Parameters, ) -> <ParseBoolError as Arbitrary>::Strategy
§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: <Utf8Error as Arbitrary>::Parameters, ) -> <Utf8Error as Arbitrary>::Strategy
§impl Arbitrary for AtomicBool
impl Arbitrary for AtomicBool
type Parameters = ()
type Strategy = Map<<bool as Arbitrary>::Strategy, fn(_: bool) -> AtomicBool>
fn arbitrary_with( _args: <AtomicBool as Arbitrary>::Parameters, ) -> <AtomicBool as Arbitrary>::Strategy
§impl Arbitrary for AtomicIsize
impl Arbitrary for AtomicIsize
type Parameters = ()
type Strategy = Map<<isize as Arbitrary>::Strategy, fn(_: isize) -> AtomicIsize>
fn arbitrary_with( _args: <AtomicIsize as Arbitrary>::Parameters, ) -> <AtomicIsize as Arbitrary>::Strategy
§impl Arbitrary for AtomicUsize
impl Arbitrary for AtomicUsize
type Parameters = ()
type Strategy = Map<<usize as Arbitrary>::Strategy, fn(_: usize) -> AtomicUsize>
fn arbitrary_with( _args: <AtomicUsize as Arbitrary>::Parameters, ) -> <AtomicUsize as Arbitrary>::Strategy
§impl Arbitrary for JoinPathsError
impl Arbitrary for JoinPathsError
type Parameters = ()
type Strategy = LazyJust<JoinPathsError, fn() -> JoinPathsError>
fn arbitrary_with( _args: <JoinPathsError as Arbitrary>::Parameters, ) -> <JoinPathsError as Arbitrary>::Strategy
§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: <OsString as Arbitrary>::Parameters, ) -> <OsString as Arbitrary>::Strategy
§impl Arbitrary for DirBuilder
impl Arbitrary for DirBuilder
type Parameters = ()
type Strategy = Map<<bool as Arbitrary>::Strategy, fn(_: bool) -> DirBuilder>
fn arbitrary_with( _args: <DirBuilder as Arbitrary>::Parameters, ) -> <DirBuilder as Arbitrary>::Strategy
§impl Arbitrary for DefaultHasher
impl Arbitrary for DefaultHasher
type Parameters = ()
type Strategy = LazyJust<DefaultHasher, fn() -> DefaultHasher>
fn arbitrary_with( _args: <DefaultHasher as Arbitrary>::Parameters, ) -> <DefaultHasher as Arbitrary>::Strategy
§impl Arbitrary for RandomState
impl Arbitrary for RandomState
type Parameters = ()
type Strategy = LazyJust<RandomState, fn() -> RandomState>
fn arbitrary_with( _args: <RandomState as Arbitrary>::Parameters, ) -> <RandomState as Arbitrary>::Strategy
§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)