pub trait Arbitrary<'a>: Sized + Debug {
type Parameters: Default;
type Strategy: Strategy<Value = Self::ValueTree>;
type ValueTree: ValueTree<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 function arbitrary which generates a Strategy for
producing arbitrary values of the implementing type (Self).
This trait is the equivalent of
Haskell QuickCheck’s implementation of Arbitrary.
In this interpretation of Arbitray, Strategy is the equivalent of
the Gen monad.
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()).
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<'a> Arbitrary<'a> for FromBytesWithNulError
impl<'a> Arbitrary<'a> for FromBytesWithNulError
type ValueTree = <<FromBytesWithNulError as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = ()
type Strategy = Map<<Option<u16> as Arbitrary<'a>>::Strategy, SFnMap<Option<u16>, FromBytesWithNulError>>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for IpAddr
impl<'a> Arbitrary<'a> for IpAddr
type ValueTree = <<IpAddr as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = ()
type Strategy = TupleUnion<((u32, Map<<Ipv4Addr as Arbitrary<'a>>::Strategy, FromMapper<<<<Ipv4Addr as Arbitrary<'a>>::Strategy as Strategy>::Value as ValueTree>::Value, IpAddr>>), (u32, Map<<Ipv6Addr as Arbitrary<'a>>::Strategy, FromMapper<<<<Ipv6Addr as Arbitrary<'a>>::Strategy as Strategy>::Value as ValueTree>::Value, IpAddr>>))>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for SocketAddr
impl<'a> Arbitrary<'a> for SocketAddr
type ValueTree = <<SocketAddr as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = ()
type Strategy = TupleUnion<((u32, Map<<SocketAddrV4 as Arbitrary<'a>>::Strategy, FromMapper<<<<SocketAddrV4 as Arbitrary<'a>>::Strategy as Strategy>::Value as ValueTree>::Value, SocketAddr>>), (u32, Map<<SocketAddrV6 as Arbitrary<'a>>::Strategy, FromMapper<<<<SocketAddrV6 as Arbitrary<'a>>::Strategy as Strategy>::Value as ValueTree>::Value, SocketAddr>>))>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for FpCategory
impl<'a> Arbitrary<'a> for FpCategory
type ValueTree = <<FpCategory as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = ()
type Strategy = TupleUnion<((u32, Just<FpCategory>), (u32, Just<FpCategory>), (u32, Just<FpCategory>), (u32, Just<FpCategory>), (u32, Just<FpCategory>))>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for Ordering
impl<'a> Arbitrary<'a> for Ordering
type ValueTree = <<Ordering as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = ()
type Strategy = TupleUnion<((u32, Just<Ordering>), (u32, Just<Ordering>), (u32, Just<Ordering>), (u32, Just<Ordering>), (u32, Just<Ordering>))>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for VarError
impl<'a> Arbitrary<'a> for VarError
type ValueTree = <<VarError as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = ()
type Strategy = TupleUnion<((u32, Just<VarError>), (u32, Map<Box<dyn Strategy<Value = Box<dyn ValueTree<Value = OsString>>>>, SFnMap<<<Box<dyn Strategy<Value = Box<dyn ValueTree<Value = OsString>>>> as Strategy>::Value as ValueTree>::Value, VarError>>))>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for SeekFrom
impl<'a> Arbitrary<'a> for SeekFrom
type ValueTree = <<SeekFrom as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = ()
type Strategy = TupleUnion<((u32, Map<<u64 as Arbitrary<'a>>::Strategy, SFnMap<u64, SeekFrom>>), (u32, Map<<i64 as Arbitrary<'a>>::Strategy, SFnMap<i64, SeekFrom>>), (u32, Map<<i64 as Arbitrary<'a>>::Strategy, SFnMap<i64, SeekFrom>>))>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for RecvTimeoutError
impl<'a> Arbitrary<'a> for RecvTimeoutError
type ValueTree = <<RecvTimeoutError as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = ()
type Strategy = TupleUnion<((u32, Just<RecvTimeoutError>), (u32, Just<RecvTimeoutError>))>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for TryRecvError
impl<'a> Arbitrary<'a> for TryRecvError
type ValueTree = <<TryRecvError as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = ()
type Strategy = TupleUnion<((u32, Just<TryRecvError>), (u32, Just<TryRecvError>))>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for Box<str>
impl<'a> Arbitrary<'a> for Box<str>
type ValueTree = <<Box<str> as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = StringParam<'a>
type Strategy = Map<<String as Arbitrary<'a>>::Strategy, FromMapper<<<<String as Arbitrary<'a>>::Strategy as Strategy>::Value as ValueTree>::Value, Box<str>>>
fn arbitrary_with(a: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for Box<CStr>
impl<'a> Arbitrary<'a> for Box<CStr>
type ValueTree = <<Box<CStr> as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = SizeBounds
type Strategy = Map<<CString as Arbitrary<'a>>::Strategy, FromMapper<<<<CString as Arbitrary<'a>>::Strategy as Strategy>::Value as ValueTree>::Value, Box<CStr>>>
fn arbitrary_with(a: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for Box<OsStr>
impl<'a> Arbitrary<'a> for Box<OsStr>
type ValueTree = <<Box<OsStr> as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = <String as Arbitrary<'a>>::Parameters
type Strategy = Map<<OsString as Arbitrary<'a>>::Strategy, FromMapper<<<<OsString as Arbitrary<'a>>::Strategy as Strategy>::Value as ValueTree>::Value, Box<OsStr>>>
fn arbitrary_with(a: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for CString
impl<'a> Arbitrary<'a> for CString
type ValueTree = <<CString as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = SizeBounds
type Strategy = Map<VecStrategy<Range<u8>>, SFnMap<<<VecStrategy<Range<u8>> as Strategy>::Value as ValueTree>::Value, CString>>
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for IntoStringError
impl<'a> Arbitrary<'a> for IntoStringError
type ValueTree = <<IntoStringError as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = ()
type Strategy = Map<Box<dyn Strategy<Value = Box<dyn ValueTree<Value = Vec<u8>>>>>, SFnMap<<<Box<dyn Strategy<Value = Box<dyn ValueTree<Value = Vec<u8>>>>> as Strategy>::Value as ValueTree>::Value, IntoStringError>>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for Rc<str>
impl<'a> Arbitrary<'a> for Rc<str>
type ValueTree = <<Rc<str> as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = StringParam<'a>
type Strategy = Map<<String as Arbitrary<'a>>::Strategy, FromMapper<<<<String as Arbitrary<'a>>::Strategy as Strategy>::Value as ValueTree>::Value, Rc<str>>>
fn arbitrary_with(a: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for Rc<CStr>
impl<'a> Arbitrary<'a> for Rc<CStr>
type ValueTree = <<Rc<CStr> as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = SizeBounds
type Strategy = Map<<CString as Arbitrary<'a>>::Strategy, FromMapper<<<<CString as Arbitrary<'a>>::Strategy as Strategy>::Value as ValueTree>::Value, Rc<CStr>>>
fn arbitrary_with(a: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for Rc<OsStr>
impl<'a> Arbitrary<'a> for Rc<OsStr>
type ValueTree = <<Rc<OsStr> as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = <String as Arbitrary<'a>>::Parameters
type Strategy = Map<<OsString as Arbitrary<'a>>::Strategy, FromMapper<<<<OsString as Arbitrary<'a>>::Strategy as Strategy>::Value as ValueTree>::Value, Rc<OsStr>>>
fn arbitrary_with(a: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for FromUtf8Error
impl<'a> Arbitrary<'a> for FromUtf8Error
type ValueTree = <<FromUtf8Error as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = ()
type Strategy = Map<Box<dyn Strategy<Value = Box<dyn ValueTree<Value = Vec<u8>>>>>, SFnMap<<<Box<dyn Strategy<Value = Box<dyn ValueTree<Value = Vec<u8>>>>> as Strategy>::Value as ValueTree>::Value, FromUtf8Error>>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for FromUtf16Error
impl<'a> Arbitrary<'a> for FromUtf16Error
type ValueTree = <<FromUtf16Error as Arbitrary<'a>>::Strategy as Strategy>::Value
type Parameters = ()
type Strategy = Generator<FromUtf16Error, fn() -> FromUtf16Error>
fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy
Source§impl<'a> Arbitrary<'a> for String
impl<'a> Arbitrary<'a> for String
Source§fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
fn arbitrary_with(args: Self::Parameters) -> Self::Strategy
§Safety
This implementation panics if the input is not a valid regex proptest can handle.