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

derive macro for Arbitrary is hard to find #463

Closed
lolbinarycat opened this issue Jun 14, 2024 · 4 comments · Fixed by #464
Closed

derive macro for Arbitrary is hard to find #463

lolbinarycat opened this issue Jun 14, 2024 · 4 comments · Fixed by #464
Labels
documentation issues around documentation (doc comments, book, best-practices, etc)

Comments

@lolbinarycat
Copy link

probably the biggest hurdle to using proptest is the need to manually implement Arbitrary for a type. the ability to have a derive macro, even if it was really limited (eg. only unit enums) would be incredibly useful.

obviously this derive macro couldn't figure out the best methods for shrinking a value and such, but often it wouldn't need to, as a lot of types (like unit enums) don't have any meaningful way they can be shrunk.

@matthew-russo
Copy link
Member

Hi, this already exists:

https://proptest-rs.github.io/proptest/proptest-derive/index.html

https://crates.io/crates/proptest-derive

Let us know if this addresses your use case or if there are improvements you'd like to see

@matthew-russo matthew-russo added the help-request This issue is asking for advice/help on using proptest label Jun 14, 2024
@lolbinarycat lolbinarycat changed the title derive macro for Arbitrary derive macro for Arbitrary is hard to find Jun 14, 2024
@lolbinarycat
Copy link
Author

is there a reason for burying this all the way at the end? personally i would have reexported this gated under a derive feature flag like most other crates, but at the very least it should be referenced in the api docs for Arbitrary.

@matthew-russo
Copy link
Member

The two crates are documented separately so first we document the proptest crate and then we document the proptest-derive crate. We can embed some more mention of the derive macro earlier on in the book and in the api docs

@matthew-russo matthew-russo added documentation issues around documentation (doc comments, book, best-practices, etc) and removed help-request This issue is asking for advice/help on using proptest labels Jun 14, 2024
@matthew-russo
Copy link
Member

It is mentioned in this area of the book about defining a canonical strategy:
https://proptest-rs.github.io/proptest/proptest/tutorial/arbitrary.html?highlight=derive#defining-a-canonical-strategy-for-a-type

I'll add a note in the doc comments of Arbitrary.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
documentation issues around documentation (doc comments, book, best-practices, etc)
Projects
None yet
2 participants