Struct Gen

Source
pub struct Gen<A> { /* private fields */ }
Expand description

Generator that generates values.

Implementations§

Source§

impl<A: Clone + 'static> Gen<A>

Source

pub fn run(self, rng: RNG) -> (A, RNG)

Evaluates the Gen with a given RNG to produce a value.

§Arguments
  • rng - The random number generator to use
§Returns
  • A tuple (A, RNG) containing the generated value and the updated RNG state
§Examples
use prop_check_rs::gen::Gens;
use prop_check_rs::rng::RNG;
let gen = Gens::choose(1, 10);
let (value, new_rng) = gen.run(RNG::new());
assert!(value >= 1 && value <= 10);
Source

pub fn new<B>(b: State<RNG, B>) -> Gen<B>

Creates a new Gen by wrapping a State.

§Arguments
  • b - The State to wrap in a Gen
§Returns
  • A new Gen<B> containing the provided State
Source

pub fn map<B, F>(self, f: F) -> Gen<B>
where F: Fn(A) -> B + 'static, B: Clone + 'static,

Transforms the output of a Gen using a function.

§Arguments
  • f - A function to apply to the generated value
§Returns
  • A new Gen<B> that applies the function to generated values
§Type Parameters
  • B - The result type after applying the function
  • F - The function type, must be Fn(A) -> B + ’static
§Examples
use prop_check_rs::gen::Gens;
let numbers = Gens::choose(1, 10);
let doubled = numbers.map(|x| x * 2);  // Generates numbers from 2 to 20
Source

pub fn and_then<B, C, F>(self, g: Gen<B>, f: F) -> Gen<C>
where F: Fn(A, B) -> C + 'static, A: Clone, B: Clone + 'static, C: Clone + 'static,

Combines two Gens using a function that takes both of their results.

§Arguments
  • g - Another Gen to combine with this one
  • f - A function that combines the results of both Gens
§Returns
  • A new Gen<C> that combines the results of both Gens
§Type Parameters
  • B - The type of the second Gen’s output
  • C - The result type after combining both outputs
  • F - The function type, must be Fn(A, B) -> C + ’static
§Examples
use prop_check_rs::gen::Gens;
let x = Gens::choose(1, 5);
let y = Gens::choose(6, 10);
let sum = x.and_then(y, |a, b| a + b);  // Generates sums from 7 to 15
Source

pub fn flat_map<B, F>(self, f: F) -> Gen<B>
where F: Fn(A) -> Gen<B> + 'static, B: Clone + 'static,

Chains this Gen with a function that returns another Gen.

§Arguments
  • f - A function that takes the result of this Gen and returns a new Gen
§Returns
  • A new Gen<B> that represents the chained computation
§Type Parameters
  • B - The type of the resulting Gen
  • F - The function type, must be Fn(A) -> Gen + ’static
§Examples
use prop_check_rs::gen::Gens;
let numbers = Gens::choose(1, 3);
let repeated = numbers.flat_map(|n| Gens::list_of_n(n, Gens::pure(n)));

Trait Implementations§

Source§

impl<A: Clone + 'static> Clone for Gen<A>

Source§

fn clone(&self) -> Self

Returns a copy of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<A: Debug> Debug for Gen<A>

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<A> Freeze for Gen<A>

§

impl<A> !RefUnwindSafe for Gen<A>

§

impl<A> !Send for Gen<A>

§

impl<A> !Sync for Gen<A>

§

impl<A> Unpin for Gen<A>

§

impl<A> !UnwindSafe for Gen<A>

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
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.
Source§

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

Source§

fn vzip(self) -> V