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

docs - example of manual arbitrary impl #282

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

Conversation

cameron1024
Copy link
Member

Adds a section to the book for manually implementing Arbitrary, addresses #252

@cameron1024 cameron1024 changed the title example of manual arbitrary impl docs - example of manual arbitrary impl Nov 18, 2022
Comment on lines +21 to +22
x: i32,
y: i32,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use 4 spaces per convention.

Comment on lines 58 to 61
any::<(i32, i32)>() // generate 2 arbitrary i32s
.prop_filter_map(|(lower, upper)| {
Range::new(lower, upper)
})
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As caveats, we should probably point to https://altsysrq.github.io/proptest-book/proptest-derive/modifiers.html#filter and also mention that a better implementation would be to swap upper for lower when upper < lower so that filtering is avoided.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. Do you think it's worth just changing the implementation? It feels weird to have the example and then a comment after saying "actually don't do it like this" when the fix is so trivial.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's change the impl, but also, deriving is powerful enough to express the new impl easily.

@rex-remind101
Copy link
Collaborator

@cameron1024 this looks close to done :)

@Centril - i'm not sure how else to reach you or @AltSysrq , but it seems that you are the sole owners of proptest-derive still. would either of you be able to update the owners to include the publish team? thanks!

@AltSysrq
Copy link
Collaborator

would either of you be able to update the owners to include the publish team?

Added.

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.

None yet

4 participants