Struct ValueGenerator

Source
pub struct ValueGenerator { /* private fields */ }
Expand description

Context for generating single values out of strategies.

Proptest is designed to be built around “value trees”, which represent a spectrum from complex values to simpler ones. But in some contexts, like benchmarking or generating corpuses, one just wants a single value. This is a convenience struct for that.

Implementations§

Source§

impl ValueGenerator

Source

pub fn new() -> Self

Creates a new value generator with the default RNG.

Source

pub fn deterministic() -> Self

Creates a new value generator with a deterministic RNG.

This generator has a hardcoded seed, so its results are predictable across test runs. However, a new proptest version may change the seed.

Source

pub fn from_seed(seed: impl Hash) -> Self

Creates a new value generator from the given seed.

This generator is typically used with a hardcoded seed that is keyed on the input data somehow. For example, for a test fixture it may be the name of the fixture.

Source

pub fn partial_clone(&mut self) -> Self

Does a “partial clone” of the ValueGenerator, creating a new independent but deterministic RNG.

Source

pub fn generate<S: Strategy>(&mut self, strategy: S) -> S::Value

Generates a single value for this strategy.

Panics if generating the new value fails. The only situation in which this can happen is if generating the value causes too many internal rejects.

Trait Implementations§

Source§

impl Debug for ValueGenerator

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for ValueGenerator

Source§

fn default() -> ValueGenerator

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V