[go: up one dir, main page]

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 FromBytesWithNulError

Available on crate feature std only.
Source§

impl Arbitrary for IpAddr

Available on crate feature std only.
Source§

impl Arbitrary for Ipv6MulticastScope

Available on crate feature std only.
Source§

impl Arbitrary for SocketAddr

Available on crate feature std only.
Source§

impl Arbitrary for FpCategory

Source§

impl Arbitrary for Option<!>

Source§

impl Arbitrary for Option<ParseError>

Source§

impl Arbitrary for Ordering

Available on crate features std or alloc only.
Source§

impl Arbitrary for VarError

Available on non-WebAssembly and crate feature std only.
Source§

impl Arbitrary for SeekFrom

Available on crate feature std only.
Source§

impl Arbitrary for ErrorKind

Available on crate feature std only.
Source§

impl Arbitrary for Shutdown

Available on crate feature std only.
Source§

impl Arbitrary for RecvTimeoutError

Available on crate feature std only.
Source§

impl Arbitrary for TryRecvError

Available on crate feature std only.
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 Global

Available on crate feature unstable and (crate features std or alloc) only.
Source§

impl Arbitrary for Box<str>

Available on crate feature std only.
Source§

impl Arbitrary for Box<CStr>

Available on crate feature std only.
Source§

impl Arbitrary for Box<OsStr>

Available on crate feature std only.
Source§

impl Arbitrary for Box<Path>

Available on crate feature std only.

This implementation is identical to the Arbitrary implementation for PathBuf.

Source§

impl Arbitrary for CString

Available on crate feature std only.
Source§

impl Arbitrary for IntoStringError

Available on crate feature std only.
Source§

impl Arbitrary for Rc<str>

Available on crate feature std only.
Source§

impl Arbitrary for Rc<CStr>

Available on crate feature std only.
Source§

impl Arbitrary for Rc<OsStr>

Available on crate feature std only.
Source§

impl Arbitrary for Rc<Path>

Available on crate feature std only.

This implementation is identical to the Arbitrary implementation for PathBuf.

Source§

impl Arbitrary for FromUtf8Error

Available on crate feature std only.
Source§

impl Arbitrary for FromUtf16Error

Available on crate feature std only.
Source§

impl Arbitrary for String

Available on crate feature std only.
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>

Available on crate feature std only.
Source§

impl Arbitrary for Arc<CStr>

Available on crate feature std only.
Source§

impl Arbitrary for Arc<OsStr>

Available on crate feature std only.
Source§

impl Arbitrary for Arc<Path>

Available on crate feature std only.

This implementation is identical to the Arbitrary implementation for PathBuf.

Source§

impl Arbitrary for Layout

Available on crate feature unstable and (crate features std or alloc) only.
Source§

impl Arbitrary for AllocError

Available on crate feature unstable and (crate features std or alloc) only.
Source§

impl Arbitrary for EscapeDefault

Source§

impl Arbitrary for BorrowError

Source§

impl Arbitrary for BorrowMutError

Source§

impl Arbitrary for CharTryFromError

Available on crate features std or alloc only.
Source§

impl Arbitrary for ParseCharError

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

impl Arbitrary for DecodeUtf16Error

Available on crate features std or alloc only.
Source§

impl Arbitrary for EscapeDebug

Available on crate features std or alloc only.
Source§

impl Arbitrary for EscapeDefault

Available on crate features std or alloc only.
Source§

impl Arbitrary for EscapeUnicode

Available on crate features std or alloc only.
Source§

impl Arbitrary for ToLowercase

Available on crate features std or alloc only.
Source§

impl Arbitrary for ToUppercase

Available on crate features std or alloc only.
Source§

impl Arbitrary for Error

Source§

impl Arbitrary for Ipv4Addr

Available on crate feature std only.
Source§

impl Arbitrary for Ipv6Addr

Available on crate feature std only.
Source§

impl Arbitrary for AddrParseError

Available on crate feature std only.
Source§

impl Arbitrary for SocketAddrV4

Available on crate feature std only.
Source§

impl Arbitrary for SocketAddrV6

Available on crate feature std only.
Source§

impl Arbitrary for ParseFloatError

Source§

impl Arbitrary for ParseIntError

Source§

impl Arbitrary for TryFromIntError

Source§

impl Arbitrary for RangeFull

Available on crate features std or alloc only.
Source§

impl Arbitrary for ParseBoolError

Available on crate features std or alloc only.
Source§

impl Arbitrary for Utf8Error

Available on crate features std or alloc only.
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

Available on crate features std or alloc only.
Source§

impl Arbitrary for AtomicI8

Available on crate features std or alloc only.
Source§

impl Arbitrary for AtomicI16

Available on crate features std or alloc only.
Source§

impl Arbitrary for AtomicI32

Available on crate features std or alloc only.
Source§

impl Arbitrary for AtomicI64

Available on crate features std or alloc only.
Source§

impl Arbitrary for AtomicIsize

Available on crate features std or alloc only.
Source§

impl Arbitrary for AtomicU8

Available on crate features std or alloc only.
Source§

impl Arbitrary for AtomicU16

Available on crate features std or alloc only.
Source§

impl Arbitrary for AtomicU32

Available on crate features std or alloc only.
Source§

impl Arbitrary for AtomicU64

Available on crate features std or alloc only.
Source§

impl Arbitrary for AtomicUsize

Available on crate features std or alloc only.
Source§

impl Arbitrary for Duration

Available on crate feature std only.
Source§

impl Arbitrary for Args

Available on crate feature std only.
Source§

impl Arbitrary for ArgsOs

Available on crate feature std only.
Source§

impl Arbitrary for JoinPathsError

Available on crate feature std only.
Source§

impl Arbitrary for Vars

Available on crate feature std only.
Source§

impl Arbitrary for VarsOs

Available on crate feature std only.
Source§

impl Arbitrary for OsString

Available on crate feature std only.
Source§

impl Arbitrary for DirBuilder

Available on crate feature std only.
Source§

impl Arbitrary for DefaultHasher

Available on crate features std or alloc only.
Source§

impl Arbitrary for RandomState

Available on crate features std or alloc only.
Source§

impl Arbitrary for Error

Available on crate feature std only.
Source§

impl Arbitrary for Stderr

Available on crate feature std only.
Source§

impl Arbitrary for Stdin

Available on crate feature std only.
Source§

impl Arbitrary for Stdout

Available on crate feature std only.
Source§

impl Arbitrary for Empty

Available on crate feature std only.
Source§

impl Arbitrary for Repeat

Available on crate feature std only.
Source§

impl Arbitrary for Sink

Available on crate feature std only.
Source§

impl Arbitrary for PathBuf

Available on crate feature std only.

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

Available on crate feature std only.
Source§

impl Arbitrary for Barrier

Available on crate feature std only.
Source§

impl Arbitrary for BarrierWaitResult

Available on crate feature std only.
Source§

impl Arbitrary for RecvError

Available on crate feature std only.
Source§

impl Arbitrary for Once

Available on crate feature std only.
Source§

impl Arbitrary for Condvar

Available on crate feature std only.
Source§

impl Arbitrary for WaitTimeoutResult

Available on crate feature std only.
Source§

impl Arbitrary for Builder

Available on crate feature std only.
Source§

impl Arbitrary for Instant

Available on crate feature std only.
Source§

impl Arbitrary for SystemTime

Available on crate feature std only.
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>)

Available on crate feature std only.
Source§

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

Available on crate feature std only.
Source§

impl<A> Arbitrary for Empty<A>

Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate feature std only.
Source§

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

Available on crate feature std only.
Source§

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

Available on crate feature std only.
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>

Available on crate feature std only.
Source§

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

Available on crate feature std only.
Source§

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

Available on crate features std or alloc only.
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>

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
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 StepBy<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>

Available on crate feature std only.
Source§

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

Available on crate feature std only.
Source§

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

Available on crate feature std only.
Source§

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

Available on crate feature std only.
Source§

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

Available on crate features std or alloc only.
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<!, A>

Source§

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

Source§

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

Source§

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

Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
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 Saturating<A>

Source§

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

Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Available on crate features std or alloc only.
Source§

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

Source§

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

Available on crate feature std only.
Source§

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

Source§

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

Available on crate feature std only.
Source§

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

Available on crate feature std only.
Source§

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

Available on crate feature std only.
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>

Available on crate features std or alloc only.
Source§

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

Available on crate feature std only.
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>

Available on crate feature std only.
Source§

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

Source§

impl<Y: Arbitrary, R: Arbitrary> Arbitrary for CoroutineState<Y, R>

Available on crate features std or alloc only.

Implementors§