Closed emk closed 7 years ago
Nice writeup! I think this is desirable yes, assuming it doesn't require nightly Rust (which I think is true nowadays). But this has been a long wanted feature, which makes it a dupe of #98. :-)
Hah! I looked for that but didn't see it. Thank you.
Assuming we have a struct type:
…it's fairly mechanical to write an
Arbitrary
impl for it:It might be more general to also use a tuple
let (left, top, width, bottom) = g.gen()
inarbitrary
, although that would need some constraints to ensure thatleft + width
fits in ausize
. But the basic idea seems to work, and it could be easily generalized to enums.However, it would be even easier if I could write something like:
This could be implemented for stable Rust using Macros 1.1. It would only work for types where correctness is enforced by the type system. Again, the challenge is what to do about constraints, such as the one on
left + width
not overflowing.Does this seem like a desirable feature? It might be fun to poke at someday, if nobody beats me to it. :-)