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

    // Provided method
    fn shrink(&self) -> Box<dyn Iterator<Item = Self>, Global> { ... }
}
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>, Global>

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.

Implementations on Foreign Types§

source§

impl Arbitrary for u128

source§

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

source§

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

source§

impl Arbitrary for i8

source§

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

source§

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

source§

impl Arbitrary for u8

source§

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

source§

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

source§

impl Arbitrary for Ipv6Addr

source§

impl Arbitrary for RangeFull

source§

impl Arbitrary for NonZeroU128

source§

impl Arbitrary for SystemTime

source§

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

source§

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

source§

impl Arbitrary for CString

source§

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

source§

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

source§

impl<T> Arbitrary for VecDeque<T, Global>where T: Arbitrary,

source§

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

source§

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

source§

impl Arbitrary for SocketAddrV6

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl Arbitrary for PathBuf

source§

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

source§

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

source§

impl Arbitrary for f32

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl Arbitrary for i32

source§

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

source§

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

source§

impl Arbitrary for u32

source§

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

source§

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

source§

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

source§

fn arbitrary(g: &mut Gen) -> HashSet<T, S>

source§

fn shrink(&self) -> Box<dyn Iterator<Item = HashSet<T, S>>, Global>

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 Arbitrary for NonZeroU32

source§

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

source§

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

source§

impl Arbitrary for u16

source§

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

source§

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

source§

impl Arbitrary for SocketAddrV4

source§

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

source§

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

source§

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

source§

impl Arbitrary for i64

source§

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

source§

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

source§

impl Arbitrary for IpAddr

source§

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

source§

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

source§

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

source§

impl Arbitrary for f64

source§

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

source§

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

source§

impl<T> Arbitrary for LinkedList<T, Global>where T: Arbitrary,

source§

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

source§

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

source§

impl<T> Arbitrary for BinaryHeap<T, Global>where T: Arbitrary + Ord,

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl Arbitrary for u64

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl Arbitrary for String

source§

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

source§

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

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,)>, Global>

source§

impl Arbitrary for i128

source§

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

source§

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

source§

impl Arbitrary for ()

source§

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

source§

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

source§

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

source§

impl Arbitrary for Duration

source§

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

source§

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

source§

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

source§

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

source§

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

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)>, Global>

source§

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

source§

impl Arbitrary for usize

source§

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

source§

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

source§

impl Arbitrary for SocketAddr

source§

impl Arbitrary for i16

source§

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

source§

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

source§

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

source§

impl Arbitrary for char

source§

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

source§

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

source§

impl<A> Arbitrary for Box<A, Global>where A: Arbitrary,

source§

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

source§

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

source§

impl Arbitrary for bool

source§

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

source§

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

source§

impl Arbitrary for NonZeroU64

source§

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

source§

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

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)>, Global>

source§

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

source§

impl Arbitrary for isize

source§

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

source§

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

source§

impl Arbitrary for Ipv4Addr

source§

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

source§

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

source§

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

source§

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

source§

impl<T> Arbitrary for BTreeSet<T, Global>where T: Arbitrary + Ord,

source§

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

source§

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

source§

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

source§

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

source§

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

source§

impl<A> Arbitrary for Vec<A, Global>where A: Arbitrary,

source§

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

source§

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

source§

impl Arbitrary for OsString

source§

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

source§

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

source§

impl Arbitrary for NonZeroUsize

source§

impl Arbitrary for NonZeroU8

source§

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

source§

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

source§

impl Arbitrary for NonZeroU16

source§

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

source§

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

Implementors§