proptest::arbitrary

Trait Arbitrary

Source
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 Strategys 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§

Source

type Parameters: Default

The type of parameters that arbitrary_with accepts for configuration of the generated Strategy. Parameters must implement Default.

Source

type Strategy: Strategy<Value = Self>

The type of Strategy used to generate values of type Self.

Required Methods§

Source

fn arbitrary_with(args: Self::Parameters) -> Self::Strategy

Generates a Strategy for producing arbitrary values of type the implementing type (Self). The strategy is passed the arguments given in args.

If you wish to use the default() arguments, use arbitrary instead.

Provided Methods§

Source

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 Ordering

Source§

impl Arbitrary for IpAddr

Source§

impl Arbitrary for SocketAddr

Source§

impl Arbitrary for FpCategory

Source§

impl Arbitrary for Option<ParseError>

Source§

impl Arbitrary for Ordering

Source§

impl Arbitrary for VarError

Source§

impl Arbitrary for SeekFrom

Source§

impl Arbitrary for ErrorKind

Source§

impl Arbitrary for Shutdown

Source§

impl Arbitrary for RecvTimeoutError

Source§

impl Arbitrary for TryRecvError

Source§

impl Arbitrary for bool

Source§

impl Arbitrary for char

Source§

impl Arbitrary for f32

Source§

impl Arbitrary for f64

Source§

impl Arbitrary for i8

Source§

impl Arbitrary for i16

Source§

impl Arbitrary for i32

Source§

impl Arbitrary for i64

Source§

impl Arbitrary for i128

Source§

impl Arbitrary for isize

Source§

impl Arbitrary for u8

Source§

impl Arbitrary for u16

Source§

impl Arbitrary for u32

Source§

impl Arbitrary for u64

Source§

impl Arbitrary for u128

Source§

impl Arbitrary for ()

Source§

impl Arbitrary for usize

Source§

impl Arbitrary for Box<str>

Source§

impl Arbitrary for Box<CStr>

Source§

impl Arbitrary for Box<OsStr>

Source§

impl Arbitrary for Box<Path>

This implementation is identical to the Arbitrary implementation for PathBuf.

Source§

impl Arbitrary for CString

Source§

impl Arbitrary for IntoStringError

Source§

impl Arbitrary for Rc<str>

Source§

impl Arbitrary for Rc<Path>

This implementation is identical to the Arbitrary implementation for PathBuf.

Source§

impl Arbitrary for FromUtf8Error

Source§

impl Arbitrary for FromUtf16Error

Source§

impl Arbitrary for String

Source§

fn arbitrary_with(args: Self::Parameters) -> Self::Strategy

§Panics

This implementation panics if the input is not a valid regex proptest can handle.

Source§

type Parameters = StringParam

Source§

type Strategy = &'static str

Source§

impl Arbitrary for Arc<str>

Source§

impl Arbitrary for Arc<Path>

This implementation is identical to the Arbitrary implementation for PathBuf.

Source§

impl Arbitrary for EscapeDefault

Source§

impl Arbitrary for BorrowError

Source§

impl Arbitrary for BorrowMutError

Source§

impl Arbitrary for ParseCharError

Source§

impl Arbitrary for DecodeUtf16<<Vec<u16> as IntoIterator>::IntoIter>

Source§

impl Arbitrary for DecodeUtf16Error

Source§

impl Arbitrary for EscapeDebug

Source§

impl Arbitrary for EscapeDefault

Source§

impl Arbitrary for EscapeUnicode

Source§

impl Arbitrary for FromBytesWithNulError

Source§

impl Arbitrary for Error

Source§

impl Arbitrary for Ipv4Addr

Source§

impl Arbitrary for Ipv6Addr

Source§

impl Arbitrary for AddrParseError

Source§

impl Arbitrary for SocketAddrV4

Source§

impl Arbitrary for SocketAddrV6

Source§

impl Arbitrary for ParseFloatError

Source§

impl Arbitrary for ParseIntError

Source§

impl Arbitrary for RangeFull

Source§

impl Arbitrary for ParseBoolError

Source§

impl Arbitrary for Utf8Error

Source§

type Parameters = ()

Source§

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§

fn arbitrary_with(_args: Self::Parameters) -> Self::Strategy

Source§

impl Arbitrary for AtomicBool

Source§

impl Arbitrary for AtomicIsize

Source§

impl Arbitrary for AtomicUsize

Source§

impl Arbitrary for Duration

Source§

impl Arbitrary for Args

Source§

impl Arbitrary for ArgsOs

Source§

impl Arbitrary for JoinPathsError

Source§

impl Arbitrary for Vars

Source§

impl Arbitrary for VarsOs

Source§

impl Arbitrary for OsString

Source§

impl Arbitrary for DirBuilder

Source§

impl Arbitrary for DefaultHasher

Source§

impl Arbitrary for RandomState

Source§

impl Arbitrary for Error

Source§

impl Arbitrary for Stderr

Source§

impl Arbitrary for Stdin

Source§

impl Arbitrary for Stdout

Source§

impl Arbitrary for Empty

Source§

impl Arbitrary for Repeat

Source§

impl Arbitrary for Sink

Source§

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§

type Parameters = PathParams

Source§

type Strategy = Map<<PathParamsOutput as Arbitrary>::Strategy, fn(_: PathParamsOutput) -> PathBuf>

Source§

fn arbitrary_with(args: Self::Parameters) -> Self::Strategy

Source§

impl Arbitrary for StripPrefixError

Source§

impl Arbitrary for Barrier

Source§

impl Arbitrary for BarrierWaitResult

Source§

impl Arbitrary for Condvar

Source§

impl Arbitrary for WaitTimeoutResult

Source§

impl Arbitrary for RecvError

Source§

impl Arbitrary for Once

Source§

impl Arbitrary for Builder

Source§

impl Arbitrary for Instant

Source§

impl Arbitrary for SystemTime

Source§

impl Arbitrary for NonZeroI8

Source§

impl Arbitrary for NonZeroI16

Source§

impl Arbitrary for NonZeroI32

Source§

impl Arbitrary for NonZeroI64

Source§

impl Arbitrary for NonZeroI128

Source§

impl Arbitrary for NonZeroIsize

Source§

impl Arbitrary for NonZeroU8

Source§

impl Arbitrary for NonZeroU16

Source§

impl Arbitrary for NonZeroU32

Source§

impl Arbitrary for NonZeroU64

Source§

impl Arbitrary for NonZeroU128

Source§

impl Arbitrary for NonZeroUsize

Source§

impl<'a, T: 'a + Clone, A: Arbitrary + Iterator<Item = &'a T>> Arbitrary for Cloned<A>

Source§

impl<A> Arbitrary for (Sender<A>, Receiver<A>)

Source§

impl<A> Arbitrary for (SyncSender<A>, Receiver<A>)

Source§

impl<A> Arbitrary for Empty<A>

Source§

impl<A: PartialOrd + Arbitrary> Arbitrary for Range<A>

Source§

impl<A: PartialOrd + Arbitrary> Arbitrary for RangeInclusive<A>

Source§

impl<A: Debug> Arbitrary for (Sender<A>, IntoIter<A>)

Source§

impl<A: Debug> Arbitrary for (SyncSender<A>, IntoIter<A>)

Source§

impl<A: BufRead + Arbitrary> Arbitrary for Split<A>

Source§

type Parameters = <A as Arbitrary>::Parameters

Source§

type Strategy = Map<<(A, u8) as Arbitrary>::Strategy, fn(_: (A, u8)) -> Split<A>>

Source§

fn arbitrary_with(args: Self::Parameters) -> Self::Strategy

Source§

impl<A: Read + Arbitrary> Arbitrary for Take<A>

Source§

type Parameters = <A as Arbitrary>::Parameters

Source§

type Strategy = Map<<(A, u64) as Arbitrary>::Strategy, fn(_: (A, u64)) -> Take<A>>

Source§

fn arbitrary_with(args: Self::Parameters) -> Self::Strategy

Source§

impl<A: Read + Arbitrary, B: Read + Arbitrary> Arbitrary for Chain<A, B>

Source§

impl<A: Arbitrary + Borrow<B>, B: ToOwned<Owned = A> + Debug + ?Sized> Arbitrary for Cow<'static, B>

Source§

type Parameters = <A as Arbitrary>::Parameters

Source§

type Strategy = Map<<A as Arbitrary>::Strategy, fn(_: A) -> Cow<'static, B>>

Source§

fn arbitrary_with(args: Self::Parameters) -> Self::Strategy

Source§

impl<A: Arbitrary + Clone> Arbitrary for Repeat<A>

Source§

impl<A: Arbitrary + Ord> Arbitrary for BinaryHeap<A>

Source§

impl<A: Arbitrary + Ord> Arbitrary for IntoIter<A>

Source§

impl<A: Arbitrary + Ord> Arbitrary for BTreeSet<A>

Source§

impl<A: Arbitrary + Ord> Arbitrary for IntoIter<A>

Source§

impl<A: Arbitrary + Ord, B: Arbitrary> Arbitrary for BTreeMap<A, B>

Source§

impl<A: Arbitrary + Ord, B: Arbitrary> Arbitrary for IntoIter<A, B>

Source§

impl<A: Arbitrary + Hash + Eq> Arbitrary for HashSet<A>

Source§

impl<A: Arbitrary + Hash + Eq> Arbitrary for IntoIter<A>

Source§

impl<A: Arbitrary + Hash + Eq, B: Arbitrary> Arbitrary for HashMap<A, B>

Source§

impl<A: Arbitrary + Hash + Eq, B: Arbitrary> Arbitrary for IntoIter<A, B>

Source§

type Parameters = <HashMap<A, B> as Arbitrary>::Parameters

Source§

type Strategy = Map<<HashMap<A, B> as Arbitrary>::Strategy, fn(_: HashMap<A, B>) -> IntoIter<A, B>>

Source§

fn arbitrary_with(args: Self::Parameters) -> Self::Strategy

Source§

impl<A: Arbitrary + DoubleEndedIterator> Arbitrary for Rev<A>

Source§

impl<A: Arbitrary + Iterator + Clone> Arbitrary for Cycle<A>

Source§

impl<A: Arbitrary + Iterator> Arbitrary for Enumerate<A>

Source§

impl<A: Arbitrary + Iterator> Arbitrary for Fuse<A>

Source§

impl<A: Arbitrary + Iterator> Arbitrary for Skip<A>

Source§

impl<A: Arbitrary + Iterator> Arbitrary for Take<A>

Source§

impl<A: Arbitrary + Iterator<Item = T>, T: Debug> Arbitrary for Peekable<A>

Source§

impl<A: Arbitrary + Iterator, B: Arbitrary + Iterator> Arbitrary for Zip<A, B>

Source§

impl<A: Arbitrary + Copy> Arbitrary for Cell<A>

Source§

impl<A: Arbitrary + BufRead> Arbitrary for Lines<A>

Source§

impl<A: Arbitrary + Read> Arbitrary for BufReader<A>

Source§

impl<A: Arbitrary + Write> Arbitrary for BufWriter<A>

Source§

impl<A: Arbitrary + Write> Arbitrary for LineWriter<A>

Source§

impl<A: Arbitrary> Arbitrary for Bound<A>

Source§

type Parameters = <A as Arbitrary>::Parameters

Source§

type Strategy = TupleUnion<((u32, Arc<Map<Arc<<A as Arbitrary>::Strategy>, fn(_: <Arc<<A as Arbitrary>::Strategy> as Strategy>::Value) -> Bound<A>>>), (u32, Arc<Map<Arc<<A as Arbitrary>::Strategy>, fn(_: <Arc<<A as Arbitrary>::Strategy> as Strategy>::Value) -> Bound<A>>>), (u32, Arc<LazyJust<Bound<A>, fn() -> Bound<A>>>))>

Source§

fn arbitrary_with(args: Self::Parameters) -> Self::Strategy

Source§

impl<A: Arbitrary> Arbitrary for Option<A>

Source§

impl<A: Arbitrary> Arbitrary for Result<ParseError, A>

Source§

impl<A: Arbitrary> Arbitrary for Result<A, ParseError>

Source§

impl<A: Arbitrary> Arbitrary for Box<[A]>

Source§

impl<A: Arbitrary> Arbitrary for Box<A>

Source§

impl<A: Arbitrary> Arbitrary for IntoIter<A>

Source§

impl<A: Arbitrary> Arbitrary for LinkedList<A>

Source§

impl<A: Arbitrary> Arbitrary for IntoIter<A>

Source§

impl<A: Arbitrary> Arbitrary for VecDeque<A>

Source§

impl<A: Arbitrary> Arbitrary for Rc<[A]>

Source§

impl<A: Arbitrary> Arbitrary for Rc<A>

Source§

impl<A: Arbitrary> Arbitrary for Arc<[A]>

Source§

impl<A: Arbitrary> Arbitrary for Arc<A>

Source§

impl<A: Arbitrary> Arbitrary for IntoIter<A>

Source§

impl<A: Arbitrary> Arbitrary for Vec<A>

Source§

impl<A: Arbitrary> Arbitrary for RefCell<A>

Source§

impl<A: Arbitrary> Arbitrary for UnsafeCell<A>

Source§

impl<A: Arbitrary> Arbitrary for Reverse<A>

Source§

impl<A: Arbitrary> Arbitrary for Once<A>

Source§

impl<A: Arbitrary> Arbitrary for Discriminant<A>

Source§

impl<A: Arbitrary> Arbitrary for Wrapping<A>

Source§

impl<A: Arbitrary> Arbitrary for RangeFrom<A>

Source§

impl<A: Arbitrary> Arbitrary for RangeTo<A>

Source§

impl<A: Arbitrary> Arbitrary for RangeToInclusive<A>

Source§

impl<A: Arbitrary> Arbitrary for IntoIter<A>

Source§

impl<A: Arbitrary> Arbitrary for AssertUnwindSafe<A>

Source§

impl<A: Arbitrary> Arbitrary for IntoIter<A>

Source§

impl<A: Arbitrary> Arbitrary for Cursor<A>

Source§

impl<A: Arbitrary> Arbitrary for Mutex<A>

Source§

impl<A: Arbitrary> Arbitrary for RwLock<A>

Source§

impl<A: Arbitrary, B: Arbitrary> Arbitrary for Result<A, B>

Source§

impl<A: Arbitrary, const N: usize> Arbitrary for [A; N]

Source§

impl<H: Default + Hasher> Arbitrary for BuildHasherDefault<H>

Source§

impl<P: Clone + Default, T: Arbitrary<Parameters = P>> Arbitrary for TrySendError<T>

Source§

type Parameters = P

Source§

type Strategy = TupleUnion<((u32, Arc<Map<<T as Arbitrary>::Strategy, fn(_: T) -> TrySendError<T>>>), (u32, Arc<Map<<T as Arbitrary>::Strategy, fn(_: T) -> TrySendError<T>>>))>

Source§

fn arbitrary_with(args: Self::Parameters) -> Self::Strategy

Source§

impl<T0: Arbitrary> Arbitrary for (T0,)

Source§

impl<T0: Arbitrary, T1: Arbitrary> Arbitrary for (T0, T1)

Source§

impl<T0: Arbitrary, T1: Arbitrary, T2: Arbitrary> Arbitrary for (T0, T1, T2)

Source§

impl<T0: Arbitrary, T1: Arbitrary, T2: Arbitrary, T3: Arbitrary> Arbitrary for (T0, T1, T2, T3)

Source§

impl<T0: Arbitrary, T1: Arbitrary, T2: Arbitrary, T3: Arbitrary, T4: Arbitrary> Arbitrary for (T0, T1, T2, T3, T4)

Source§

impl<T0: Arbitrary, T1: Arbitrary, T2: Arbitrary, T3: Arbitrary, T4: Arbitrary, T5: Arbitrary> Arbitrary for (T0, T1, T2, T3, T4, T5)

Source§

impl<T0: Arbitrary, T1: Arbitrary, T2: Arbitrary, T3: Arbitrary, T4: Arbitrary, T5: Arbitrary, T6: Arbitrary> Arbitrary for (T0, T1, T2, T3, T4, T5, T6)

Source§

impl<T0: Arbitrary, T1: Arbitrary, T2: Arbitrary, T3: Arbitrary, T4: Arbitrary, T5: Arbitrary, T6: Arbitrary, T7: Arbitrary> Arbitrary for (T0, T1, T2, T3, T4, T5, T6, T7)

Source§

impl<T0: Arbitrary, T1: Arbitrary, T2: Arbitrary, T3: Arbitrary, T4: Arbitrary, T5: Arbitrary, T6: Arbitrary, T7: Arbitrary, T8: Arbitrary> Arbitrary for (T0, T1, T2, T3, T4, T5, T6, T7, T8)

Source§

impl<T0: Arbitrary, T1: Arbitrary, T2: Arbitrary, T3: Arbitrary, T4: Arbitrary, T5: Arbitrary, T6: Arbitrary, T7: Arbitrary, T8: Arbitrary, T9: Arbitrary> Arbitrary for (T0, T1, T2, T3, T4, T5, T6, T7, T8, T9)

Source§

impl<T, A: Arbitrary + Iterator<Item = T>, B: Arbitrary + Iterator<Item = T>> Arbitrary for Chain<A, B>

Source§

impl<T: Arbitrary> Arbitrary for SendError<T>

Source§

impl<T: ?Sized> Arbitrary for PhantomData<T>

Implementors§