Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convenience function for generation of recursive structures #286

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

neithernut
Copy link

When generating recursive structures, users will often use the size of the generator to bound the recursion depth. Dividing the size by the number of sub-structures appears to be a common practice. However, modifying the size of the generator passed to an implementation of Arbitrary::arbitrary would also affect the generation of sister structures if not restored after the generation of child nodes. Instead, users may choose to create a new generator instance with the target size.

The new function makes use of seed from the original generator rather than entropy. In addition to bounding recursive structures, this also allows to re-create those structures based on some initial seed.

This PR is based on #278 (in order to make use of from_seed).

jakoschiko and others added 3 commits February 9, 2021 02:13
The seed still can't be set by QuickCheck users, but the new Gen
constructor is useful for other crates that use QuickCheck only for
its Arbitrary trait.

Closes BurntSushi#277
When generating recursive structures, users will often use the size of
the generator to bound the recursion depth. Dividing the size by the
number of sub-structures appears to be a common practice. However,
modifying the size of the generator passed to an implementation of
`Arbitrary::arbitrary` would also affect the generation of sister
structures if not restored after the generation of child nodes.

Instead, users can create a new generator instance with the target size.
Historically, this would be the only option since public API for setting
the size of an existing generator was only introduced recently. This
change introduces a convenience function for creating such a generator.

The new function makes use of seed from the original generator rather
than entropy. In addition to bounding recursive structures, this also
allows to re-create those structures based on some initial seed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants