Description
Currently, it is impossible to have a S: Strategy
where ValueOf<S>
is non-owned.
Examples:
- We have a base strategy
T
whereValueOf<T>
is owned, and then we use that to make a strategy whereValueOf<S> = &'a ValueOf<T>
- This will not type check. - Derived types, for example:
Cow<'a, X>
.
Generally, I think that, any type that has a lifetime can't be generated.
Being able to generate types with lifetimes in them is however useful when you have lifetimes somewhere deep in the hierarchy of a type. To be able to do this soundly, the ValueTree
must perhaps have a notion of Owned
(which defaults to Value
) in addition to Value
(which may be borrowed). Then TestRunner
will return the Owned
type instead of Value
, but the function under test receives Value
.
I tried to implement this and got TestRunner
to compile, but no strategies would compile.
Solving this may require generic associated types (GAT). I'll experiment with it once we have GAT in nightly.
There's also *const T
and *mut T
. While it is possible to give a sound strategy for these by Box::leak
, this may cause problems since tests for large data types may leak huge amounts of memory. This could perhaps be mitigated by letting the ValueTree
store the previous value of .current()
, and whenever .current()
happens, the old value is deallocated. The last value needs to be persisted in the TestRunner
somehow if the entire ValueTree
did not fail so that it can be cleared.
I'd like your thought's on the desirability of these features.