Trait quickcheck::Arbitrary

source ·
pub trait Arbitrary: Clone + 'static {
    // Required method
    fn arbitrary(g: &mut Gen) -> Self;

    // Provided method
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>> { ... }
}
Expand description

Arbitrary describes types whose values can be randomly generated and shrunk.

Aside from shrinking, Arbitrary is different from typical RNGs in that it respects Gen::size() for controlling how much memory a particular value uses, for practical purposes. For example, Vec::arbitrary() respects Gen::size() to decide the maximum len() of the vector. This behavior is necessary due to practical speed and size limitations. Conversely, i32::arbitrary() ignores size() since all i32 values require O(1) memory and operations between i32s require O(1) time (with the exception of exponentiation).

Additionally, all types that implement Arbitrary must also implement Clone.

Required Methods§

source

fn arbitrary(g: &mut Gen) -> Self

Return an arbitrary value.

Implementations should respect Gen::size() when decisions about how big a particular value should be. Implementations should generally defer to other Arbitrary implementations to generate other random values when necessary. The Gen type also offers a few RNG helper routines.

Provided Methods§

source

fn shrink(&self) -> Box<dyn Iterator<Item = Self>>

Return an iterator of values that are smaller than itself.

The way in which a value is “smaller” is implementation defined. In some cases, the interpretation is obvious: shrinking an integer should produce integers smaller than itself. Others are more complex, for example, shrinking a Vec should both shrink its size and shrink its component values.

The iterator returned should be bounded to some reasonable size.

It is always correct to return an empty iterator, and indeed, this is the default implementation. The downside of this approach is that witnesses to failures in properties will be more inscrutable.

Object Safety§

This trait is not object safe.

Implementations on Foreign Types§

source§

impl Arbitrary for IpAddr

source§

impl Arbitrary for SocketAddr

source§

impl Arbitrary for bool

source§

fn arbitrary(g: &mut Gen) -> bool

source§

fn shrink(&self) -> Box<dyn Iterator<Item = bool>>

source§

impl Arbitrary for char

source§

fn arbitrary(g: &mut Gen) -> char

source§

fn shrink(&self) -> Box<dyn Iterator<Item = char>>

source§

impl Arbitrary for f32

source§

fn arbitrary(g: &mut Gen) -> f32

source§

fn shrink(&self) -> Box<dyn Iterator<Item = f32>>

source§

impl Arbitrary for f64

source§

fn arbitrary(g: &mut Gen) -> f64

source§

fn shrink(&self) -> Box<dyn Iterator<Item = f64>>

source§

impl Arbitrary for i8

source§

fn arbitrary(g: &mut Gen) -> i8

source§

fn shrink(&self) -> Box<dyn Iterator<Item = i8>>

source§

impl Arbitrary for i16

source§

fn arbitrary(g: &mut Gen) -> i16

source§

fn shrink(&self) -> Box<dyn Iterator<Item = i16>>

source§

impl Arbitrary for i32

source§

fn arbitrary(g: &mut Gen) -> i32

source§

fn shrink(&self) -> Box<dyn Iterator<Item = i32>>

source§

impl Arbitrary for i64

source§

fn arbitrary(g: &mut Gen) -> i64

source§

fn shrink(&self) -> Box<dyn Iterator<Item = i64>>

source§

impl Arbitrary for i128

source§

fn arbitrary(g: &mut Gen) -> i128

source§

fn shrink(&self) -> Box<dyn Iterator<Item = i128>>

source§

impl Arbitrary for isize

source§

fn arbitrary(g: &mut Gen) -> isize

source§

fn shrink(&self) -> Box<dyn Iterator<Item = isize>>

source§

impl Arbitrary for u8

source§

fn arbitrary(g: &mut Gen) -> u8

source§

fn shrink(&self) -> Box<dyn Iterator<Item = u8>>

source§

impl Arbitrary for u16

source§

fn arbitrary(g: &mut Gen) -> u16

source§

fn shrink(&self) -> Box<dyn Iterator<Item = u16>>

source§

impl Arbitrary for u32

source§

fn arbitrary(g: &mut Gen) -> u32

source§

fn shrink(&self) -> Box<dyn Iterator<Item = u32>>

source§

impl Arbitrary for u64

source§

fn arbitrary(g: &mut Gen) -> u64

source§

fn shrink(&self) -> Box<dyn Iterator<Item = u64>>

source§

impl Arbitrary for u128

source§

fn arbitrary(g: &mut Gen) -> u128

source§

fn shrink(&self) -> Box<dyn Iterator<Item = u128>>

source§

impl Arbitrary for ()

source§

impl Arbitrary for usize

source§

fn arbitrary(g: &mut Gen) -> usize

source§

fn shrink(&self) -> Box<dyn Iterator<Item = usize>>

source§

impl Arbitrary for CString

source§

fn arbitrary(g: &mut Gen) -> Self

source§

fn shrink(&self) -> Box<dyn Iterator<Item = CString>>

source§

impl Arbitrary for String

source§

fn arbitrary(g: &mut Gen) -> String

source§

fn shrink(&self) -> Box<dyn Iterator<Item = String>>

source§

impl Arbitrary for Ipv4Addr

source§

impl Arbitrary for Ipv6Addr

source§

impl Arbitrary for SocketAddrV4

source§

impl Arbitrary for SocketAddrV6

source§

impl Arbitrary for RangeFull

source§

impl Arbitrary for Duration

source§

fn arbitrary(gen: &mut Gen) -> Self

source§

fn shrink(&self) -> Box<dyn Iterator<Item = Self>>

source§

impl Arbitrary for OsString

source§

fn arbitrary(g: &mut Gen) -> OsString

source§

fn shrink(&self) -> Box<dyn Iterator<Item = OsString>>

source§

impl Arbitrary for PathBuf

source§

fn arbitrary(g: &mut Gen) -> PathBuf

source§

fn shrink(&self) -> Box<dyn Iterator<Item = PathBuf>>

source§

impl Arbitrary for SystemTime

source§

fn arbitrary(gen: &mut Gen) -> Self

source§

fn shrink(&self) -> Box<dyn Iterator<Item = Self>>

source§

impl Arbitrary for NonZeroU8

source§

fn arbitrary(g: &mut Gen) -> NonZeroU8

source§

fn shrink(&self) -> Box<dyn Iterator<Item = NonZeroU8>>

source§

impl Arbitrary for NonZeroU16

source§

fn arbitrary(g: &mut Gen) -> NonZeroU16

source§

fn shrink(&self) -> Box<dyn Iterator<Item = NonZeroU16>>

source§

impl Arbitrary for NonZeroU32

source§

fn arbitrary(g: &mut Gen) -> NonZeroU32

source§

fn shrink(&self) -> Box<dyn Iterator<Item = NonZeroU32>>

source§

impl Arbitrary for NonZeroU64

source§

fn arbitrary(g: &mut Gen) -> NonZeroU64

source§

fn shrink(&self) -> Box<dyn Iterator<Item = NonZeroU64>>

source§

impl Arbitrary for NonZeroU128

source§

fn arbitrary(g: &mut Gen) -> NonZeroU128

source§

fn shrink(&self) -> Box<dyn Iterator<Item = NonZeroU128>>

source§

impl Arbitrary for NonZeroUsize

source§

fn arbitrary(g: &mut Gen) -> NonZeroUsize

source§

fn shrink(&self) -> Box<dyn Iterator<Item = NonZeroUsize>>

source§

impl<A> Arbitrary for (A,)
where A: Arbitrary,

source§

fn arbitrary(g: &mut Gen) -> (A,)

source§

fn shrink(&self) -> Box<dyn Iterator<Item = (A,)>>

source§

impl<A, B> Arbitrary for (A, B)
where A: Arbitrary, B: Arbitrary,

source§

fn arbitrary(g: &mut Gen) -> (A, B)

source§

fn shrink(&self) -> Box<dyn Iterator<Item = (A, B)>>

source§

impl<A, B, C> Arbitrary for (A, B, C)
where A: Arbitrary, B: Arbitrary, C: Arbitrary,

source§

fn arbitrary(g: &mut Gen) -> (A, B, C)

source§

fn shrink(&self) -> Box<dyn Iterator<Item = (A, B, C)>>

source§

impl<A, B, C, D> Arbitrary for (A, B, C, D)
where A: Arbitrary, B: Arbitrary, C: Arbitrary, D: Arbitrary,

source§

fn arbitrary(g: &mut Gen) -> (A, B, C, D)

source§

fn shrink(&self) -> Box<dyn Iterator<Item = (A, B, C, D)>>

source§

impl<A, B, C, D, E> Arbitrary for (A, B, C, D, E)
where A: Arbitrary, B: Arbitrary, C: Arbitrary, D: Arbitrary, E: Arbitrary,

source§

impl<A, B, C, D, E, F> Arbitrary for (A, B, C, D, E, F)

source§

impl<A, B, C, D, E, F, G> Arbitrary for (A, B, C, D, E, F, G)

source§

impl<A, B, C, D, E, F, G, H> Arbitrary for (A, B, C, D, E, F, G, H)

source§

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

source§

fn arbitrary(g: &mut Gen) -> Arc<A>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = Arc<A>>>

source§

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

source§

fn arbitrary(g: &mut Gen) -> Option<A>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = Option<A>>>

source§

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

source§

fn arbitrary(g: &mut Gen) -> Box<A>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = Box<A>>>

source§

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

source§

fn arbitrary(g: &mut Gen) -> Vec<A>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = Vec<A>>>

source§

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

source§

fn arbitrary(g: &mut Gen) -> Result<A, B>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = Result<A, B>>>

source§

impl<K: Arbitrary + Eq + Hash, V: Arbitrary, S: BuildHasher + Default + Clone + 'static> Arbitrary for HashMap<K, V, S>

source§

fn arbitrary(g: &mut Gen) -> Self

source§

fn shrink(&self) -> Box<dyn Iterator<Item = Self>>

source§

impl<K: Arbitrary + Ord, V: Arbitrary> Arbitrary for BTreeMap<K, V>

source§

fn arbitrary(g: &mut Gen) -> BTreeMap<K, V>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = BTreeMap<K, V>>>

source§

impl<T: Arbitrary + Clone + PartialOrd> Arbitrary for Range<T>

source§

fn arbitrary(g: &mut Gen) -> Range<T>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = Range<T>>>

source§

impl<T: Arbitrary + Clone + PartialOrd> Arbitrary for RangeFrom<T>

source§

fn arbitrary(g: &mut Gen) -> RangeFrom<T>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = RangeFrom<T>>>

source§

impl<T: Arbitrary + Clone + PartialOrd> Arbitrary for RangeInclusive<T>

source§

fn arbitrary(g: &mut Gen) -> RangeInclusive<T>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = RangeInclusive<T>>>

source§

impl<T: Arbitrary + Clone + PartialOrd> Arbitrary for RangeTo<T>

source§

fn arbitrary(g: &mut Gen) -> RangeTo<T>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = RangeTo<T>>>

source§

impl<T: Arbitrary + Clone + PartialOrd> Arbitrary for RangeToInclusive<T>

source§

fn arbitrary(g: &mut Gen) -> RangeToInclusive<T>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = RangeToInclusive<T>>>

source§

impl<T: Arbitrary + Eq + Hash, S: BuildHasher + Default + Clone + 'static> Arbitrary for HashSet<T, S>

source§

fn arbitrary(g: &mut Gen) -> Self

source§

fn shrink(&self) -> Box<dyn Iterator<Item = Self>>

source§

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

source§

fn arbitrary(g: &mut Gen) -> BinaryHeap<T>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = BinaryHeap<T>>>

source§

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

source§

fn arbitrary(g: &mut Gen) -> BTreeSet<T>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = BTreeSet<T>>>

source§

impl<T: Arbitrary> Arbitrary for Bound<T>

source§

fn arbitrary(g: &mut Gen) -> Bound<T>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = Bound<T>>>

source§

impl<T: Arbitrary> Arbitrary for LinkedList<T>

source§

fn arbitrary(g: &mut Gen) -> LinkedList<T>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = LinkedList<T>>>

source§

impl<T: Arbitrary> Arbitrary for VecDeque<T>

source§

fn arbitrary(g: &mut Gen) -> VecDeque<T>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = VecDeque<T>>>

source§

impl<T: Arbitrary> Arbitrary for Wrapping<T>

source§

fn arbitrary(g: &mut Gen) -> Wrapping<T>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = Wrapping<T>>>

Implementors§