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.

Object Safety§

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§