Generator

Struct Generator 

Source
pub struct Generator<V, F: Fn() -> V> { /* private fields */ }
Expand description

Strategy for generating Vs from an Fn() -> V. It’s not a very interesting Strategy, but required sometimes when the only means of creating an object of some type is via a function while type type is also not Clone.

Implementations§

Source§

impl<V, F: Fn() -> V> Generator<V, F>

Source

pub fn new(generator: F) -> Self

Constructs a Generator strategy.

Trait Implementations§

Source§

impl<V: Clone, F: Clone + Fn() -> V> Clone for Generator<V, F>

Source§

fn clone(&self) -> Generator<V, F>

Returns a duplicate 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<V, F: Fn() -> V> Debug for Generator<V, F>

Source§

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

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

impl<V: Debug, F: Clone + Fn() -> V> Strategy for Generator<V, F>

Source§

type Value = Generator<V, F>

The value tree generated by this Strategy. Read more
Source§

fn new_value(&self, _: &mut TestRunner) -> Result<Self::Value, String>

Generate a new value tree from the given runner. Read more
Source§

fn prop_map<O, F>(self, fun: F) -> Map<Self, F>
where O: Debug, F: Fn(<Self::Value as ValueTree>::Value) -> O, Self: Sized,

Returns a strategy which produces values transformed by the function fun. Read more
Source§

fn prop_perturb<O, F>(self, fun: F) -> Perturb<Self, F>
where O: Debug, F: Fn(<Self::Value as ValueTree>::Value, XorShiftRng) -> O, Self: Sized,

Returns a strategy which produces values transformed by the function fun, which is additionally given a random number generator. Read more
Source§

fn prop_flat_map<S, F>(self, fun: F) -> Flatten<Map<Self, F>>
where S: Strategy, F: Fn(<Self::Value as ValueTree>::Value) -> S, Self: Sized,

Maps values produced by this strategy into new strategies and picks values from those strategies. Read more
Source§

fn prop_ind_flat_map<S, F>(self, fun: F) -> IndFlatten<Map<Self, F>>
where S: Strategy, F: Fn(<Self::Value as ValueTree>::Value) -> S, Self: Sized,

Maps values produced by this strategy into new strategies and picks values from those strategies while considering the new strategies to be independent. Read more
Source§

fn prop_ind_flat_map2<S, F>(self, fun: F) -> IndFlattenMap<Self, F>
where S: Strategy, F: Fn(<Self::Value as ValueTree>::Value) -> S, Self: Sized,

Similar to prop_ind_flat_map(), but produces 2-tuples with the input generated from self in slot 0 and the derived strategy in slot 1. Read more
Source§

fn prop_filter<F>(self, whence: String, fun: F) -> Filter<Self, F>
where F: Fn(&<Self::Value as ValueTree>::Value) -> bool, Self: Sized,

Returns a strategy which only produces values accepted by fun. Read more
Source§

fn prop_union(self, other: Self) -> Union<Self>
where Self: Sized,

Returns a strategy which picks uniformly from self and other. Read more
Source§

fn prop_recursive<F>( self, depth: u32, desired_size: u32, expected_branch_size: u32, recurse: F, ) -> Recursive<Box<dyn Strategy<Value = Box<dyn ValueTree<Value = <Self::Value as ValueTree>::Value>>>>, F>
where F: Fn(Arc<Box<dyn Strategy<Value = Box<dyn ValueTree<Value = <Self::Value as ValueTree>::Value>>>>>) -> Box<dyn Strategy<Value = Box<dyn ValueTree<Value = <Self::Value as ValueTree>::Value>>>>, Self: Sized + 'static,

Generate a recursive structure with self items as leaves. Read more
Source§

fn prop_shuffle(self) -> Shuffle<Self>
where Self: Sized, <Self::Value as ValueTree>::Value: Shuffleable,

Shuffle the contents of the values produced by this strategy. Read more
Source§

fn boxed( self, ) -> Box<dyn Strategy<Value = Box<dyn ValueTree<Value = <Self::Value as ValueTree>::Value>>>>
where Self: Sized + 'static,

Erases the type of this Strategy so it can be passed around as a simple trait object. Read more
Source§

fn sboxed( self, ) -> Box<dyn Strategy<Value = Box<dyn ValueTree<Value = <Self::Value as ValueTree>::Value>>> + Send + Sync>
where Self: Sized + Send + Sync + 'static,

Erases the type of this Strategy so it can be passed around as a simple trait object. Read more
Source§

fn no_shrink(self) -> NoShrink<Self>
where Self: Sized,

Wraps this strategy to prevent values from being subject to shrinking. Read more
Source§

impl<V: Debug, F: Fn() -> V> ValueTree for Generator<V, F>

Source§

type Value = V

The type of the value produced by this ValueTree.
Source§

fn current(&self) -> Self::Value

Returns the current value.
Source§

fn simplify(&mut self) -> bool

Attempts to simplify the current value. Notionally, this sets the “high” value to the current value, and the current value to a “halfway point” between high and low, rounding towards low. Read more
Source§

fn complicate(&mut self) -> bool

Attempts to partially undo the last simplification. Notionally, this sets the “low” value to one plus the current value, and the current value to a “halfway point” between high and the new low, rounding towards low. Read more
Source§

impl<V: Copy, F: Copy + Fn() -> V> Copy for Generator<V, F>

Auto Trait Implementations§

§

impl<V, F> Freeze for Generator<V, F>
where F: Freeze,

§

impl<V, F> RefUnwindSafe for Generator<V, F>
where F: RefUnwindSafe,

§

impl<V, F> Send for Generator<V, F>
where F: Send,

§

impl<V, F> Sync for Generator<V, F>
where F: Sync,

§

impl<V, F> Unpin for Generator<V, F>
where F: Unpin,

§

impl<V, F> UnwindSafe for Generator<V, F>
where F: UnwindSafe,

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, U, I> LiftInto<U, I> for T
where U: LiftFrom<T, I>,

Source§

fn lift_into(self) -> U

Performs the indexed conversion.
Source§

impl<Source> Sculptor<HNil, HNil> for Source

Source§

type Remainder = Source

Source§

fn sculpt(self) -> (HNil, <Source as Sculptor<HNil, HNil>>::Remainder)

Consumes the current HList and returns an HList with the requested shape. Read more
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.