[][src]Trait quickcheck::Arbitrary

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

    pub fn shrink(&self) -> Box<dyn Iterator<Item = Self>> { ... }
}

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

pub fn arbitrary(g: &mut Gen) -> Self[src]

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.

Loading content...

Provided methods

pub fn shrink(&self) -> Box<dyn Iterator<Item = Self>>[src]

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.

Loading content...

Implementations on Foreign Types

impl Arbitrary for ()[src]

impl Arbitrary for bool[src]

impl<A: Arbitrary> Arbitrary for Option<A>[src]

impl<A: Arbitrary, B: Arbitrary> Arbitrary for Result<A, B>[src]

impl<A> Arbitrary for (A,) where
    A: Arbitrary
[src]

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

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

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

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

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
[src]

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
[src]

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
[src]

impl<A: Arbitrary> Arbitrary for Vec<A>[src]

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

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

impl<T: Arbitrary + Ord> Arbitrary for BTreeSet<T>[src]

impl<T: Arbitrary + Ord> Arbitrary for BinaryHeap<T>[src]

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

impl<T: Arbitrary> Arbitrary for LinkedList<T>[src]

impl<T: Arbitrary> Arbitrary for VecDeque<T>[src]

impl Arbitrary for IpAddr[src]

impl Arbitrary for Ipv4Addr[src]

impl Arbitrary for Ipv6Addr[src]

impl Arbitrary for SocketAddr[src]

impl Arbitrary for SocketAddrV4[src]

impl Arbitrary for SocketAddrV6[src]

impl Arbitrary for PathBuf[src]

impl Arbitrary for OsString[src]

impl Arbitrary for String[src]

impl Arbitrary for CString[src]

impl Arbitrary for char[src]

impl Arbitrary for usize[src]

impl Arbitrary for u8[src]

impl Arbitrary for u16[src]

impl Arbitrary for u32[src]

impl Arbitrary for u64[src]

impl Arbitrary for u128[src]

impl Arbitrary for isize[src]

impl Arbitrary for i8[src]

impl Arbitrary for i16[src]

impl Arbitrary for i32[src]

impl Arbitrary for i64[src]

impl Arbitrary for i128[src]

impl Arbitrary for f32[src]

impl Arbitrary for f64[src]

impl Arbitrary for NonZeroUsize[src]

impl Arbitrary for NonZeroU8[src]

impl Arbitrary for NonZeroU16[src]

impl Arbitrary for NonZeroU32[src]

impl Arbitrary for NonZeroU64[src]

impl Arbitrary for NonZeroU128[src]

impl<T: Arbitrary> Arbitrary for Wrapping<T>[src]

impl<T: Arbitrary> Arbitrary for Bound<T>[src]

impl<T: Arbitrary + Clone + PartialOrd> Arbitrary for Range<T>[src]

impl<T: Arbitrary + Clone + PartialOrd> Arbitrary for RangeInclusive<T>[src]

impl<T: Arbitrary + Clone + PartialOrd> Arbitrary for RangeFrom<T>[src]

impl<T: Arbitrary + Clone + PartialOrd> Arbitrary for RangeTo<T>[src]

impl<T: Arbitrary + Clone + PartialOrd> Arbitrary for RangeToInclusive<T>[src]

impl Arbitrary for RangeFull[src]

impl Arbitrary for Duration[src]

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

impl<A: Arbitrary + Sync> Arbitrary for Arc<A>[src]

impl Arbitrary for SystemTime[src]

Loading content...

Implementors

Loading content...