Struct TupleUnion

#[must_use = "strategies do nothing unless used"]
pub struct TupleUnion<T>(/* private field */);

Similar to Union, but internally uses a tuple to hold the strategies.

This allows better performance than vanilla Union since one does not need to resort to boxing and dynamic dispatch to handle heterogeneous strategies.

The difference between this and TupleUnion is that with this, value trees for variants that aren't picked at first are generated lazily.

Implementations

impl<T> TupleUnion<T>

fn new(tuple: T) -> Self

Wrap tuple in a TupleUnion.

The struct definition allows any T for tuple, but to be useful, it must be a 2- to 10-tuple of (u32, Arc<impl Strategy>) pairs where all strategies ultimately produce the same value. Each u32 indicates the relative weight of its corresponding strategy. You may use WA<S> as an alias for (u32, Arc<S>).

Using this constructor directly is discouraged; prefer to use prop_oneof! since it is generally clearer.

Trait Implementations

impl<A: Strategy, B: Strategy<Value = A::Value>> Strategy for TupleUnion<(WA<A>, WA<B>)>

type Tree = TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>)>;
type Value = <A as Strategy>::Value;
fn new_tree(&self, runner: &mut TestRunner) -> NewTree<Self>

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>> Strategy for TupleUnion<(WA<A>, WA<B>, WA<C>)>

type Tree = TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>)>;
type Value = <A as Strategy>::Value;
fn new_tree(&self, runner: &mut TestRunner) -> NewTree<Self>

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>, D: Strategy<Value = A::Value>> Strategy for TupleUnion<(WA<A>, WA<B>, WA<C>, WA<D>)>

type Tree = TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>, Option<LazyValueTree<D>>)>;
type Value = <A as Strategy>::Value;
fn new_tree(&self, runner: &mut TestRunner) -> NewTree<Self>

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>, D: Strategy<Value = A::Value>, E: Strategy<Value = A::Value>> Strategy for TupleUnion<(WA<A>, WA<B>, WA<C>, WA<D>, WA<E>)>

type Tree = TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>, Option<LazyValueTree<D>>, Option<LazyValueTree<E>>)>;
type Value = <A as Strategy>::Value;
fn new_tree(&self, runner: &mut TestRunner) -> NewTree<Self>

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>, D: Strategy<Value = A::Value>, E: Strategy<Value = A::Value>, F: Strategy<Value = A::Value>> Strategy for TupleUnion<(WA<A>, WA<B>, WA<C>, WA<D>, WA<E>, WA<F>)>

type Tree = TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>, Option<LazyValueTree<D>>, Option<LazyValueTree<E>>, Option<LazyValueTree<F>>)>;
type Value = <A as Strategy>::Value;
fn new_tree(&self, runner: &mut TestRunner) -> NewTree<Self>

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>, D: Strategy<Value = A::Value>, E: Strategy<Value = A::Value>, F: Strategy<Value = A::Value>, G: Strategy<Value = A::Value>> Strategy for TupleUnion<(WA<A>, WA<B>, WA<C>, WA<D>, WA<E>, WA<F>, WA<G>)>

type Tree = TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>, Option<LazyValueTree<D>>, Option<LazyValueTree<E>>, Option<LazyValueTree<F>>, Option<LazyValueTree<G>>)>;
type Value = <A as Strategy>::Value;
fn new_tree(&self, runner: &mut TestRunner) -> NewTree<Self>

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>, D: Strategy<Value = A::Value>, E: Strategy<Value = A::Value>, F: Strategy<Value = A::Value>, G: Strategy<Value = A::Value>, H: Strategy<Value = A::Value>> Strategy for TupleUnion<(WA<A>, WA<B>, WA<C>, WA<D>, WA<E>, WA<F>, WA<G>, WA<H>)>

type Tree = TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>, Option<LazyValueTree<D>>, Option<LazyValueTree<E>>, Option<LazyValueTree<F>>, Option<LazyValueTree<G>>, Option<LazyValueTree<H>>)>;
type Value = <A as Strategy>::Value;
fn new_tree(&self, runner: &mut TestRunner) -> NewTree<Self>

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>, D: Strategy<Value = A::Value>, E: Strategy<Value = A::Value>, F: Strategy<Value = A::Value>, G: Strategy<Value = A::Value>, H: Strategy<Value = A::Value>, I: Strategy<Value = A::Value>> Strategy for TupleUnion<(WA<A>, WA<B>, WA<C>, WA<D>, WA<E>, WA<F>, WA<G>, WA<H>, WA<I>)>

type Tree = TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>, Option<LazyValueTree<D>>, Option<LazyValueTree<E>>, Option<LazyValueTree<F>>, Option<LazyValueTree<G>>, Option<LazyValueTree<H>>, Option<LazyValueTree<I>>)>;
type Value = <A as Strategy>::Value;
fn new_tree(&self, runner: &mut TestRunner) -> NewTree<Self>

impl<A: Strategy, B: Strategy<Value = A::Value>, C: Strategy<Value = A::Value>, D: Strategy<Value = A::Value>, E: Strategy<Value = A::Value>, F: Strategy<Value = A::Value>, G: Strategy<Value = A::Value>, H: Strategy<Value = A::Value>, I: Strategy<Value = A::Value>, J: Strategy<Value = A::Value>> Strategy for TupleUnion<(WA<A>, WA<B>, WA<C>, WA<D>, WA<E>, WA<F>, WA<G>, WA<H>, WA<I>, WA<J>)>

type Tree = TupleUnionValueTree<(LazyValueTree<A>, Option<LazyValueTree<B>>, Option<LazyValueTree<C>>, Option<LazyValueTree<D>>, Option<LazyValueTree<E>>, Option<LazyValueTree<F>>, Option<LazyValueTree<G>>, Option<LazyValueTree<H>>, Option<LazyValueTree<I>>, Option<LazyValueTree<J>>)>;
type Value = <A as Strategy>::Value;
fn new_tree(&self, runner: &mut TestRunner) -> NewTree<Self>

impl<T: Clone> Clone for TupleUnion<T>

fn clone(&self) -> Self

impl<T: Copy> Copy for TupleUnion<T>

impl<T: Debug> Debug for TupleUnion<T>

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

Auto Trait Implementations

impl<T> Freeze for TupleUnion<T> where T: Freeze,

impl<T> RefUnwindSafe for TupleUnion<T> where T: RefUnwindSafe,

impl<T> Send for TupleUnion<T> where T: Send,

impl<T> Sync for TupleUnion<T> where T: Sync,

impl<T> Unpin for TupleUnion<T> where T: Unpin,

impl<T> UnsafeUnpin for TupleUnion<T> where T: UnsafeUnpin,

impl<T> UnwindSafe for TupleUnion<T> where T: UnwindSafe,

Blanket Implementations

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

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

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

impl<T> CloneToUninit for TupleUnion<T> where T: Clone,

impl<T> From<T> for TupleUnion<T>

impl<T> ToOwned for TupleUnion<T> where T: Clone,

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

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

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