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

fixes #589 allow min and max to be within range #733

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

Conversation

davetayls
Copy link

fixes #589

Allow min and max to be within range of the specified format

@davetayls
Copy link
Author

Hey @ahl does this fix look ok to you?

Copy link
Collaborator

@ahl ahl left a comment

Choose a reason for hiding this comment

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

Thanks for working on this; I don't think this is quite right. Please see my notes.

Comment on lines 1020 to 1021
&& (min.map(|f| f.ge(imin)).unwrap_or(false))
&& (max.map(|f| f.le(imax)).unwrap_or(false))
Copy link
Collaborator

Choose a reason for hiding this comment

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

this doesn't seem quite right. Previously the logic said: "if it's None OR is the specified bound". Now this says "if it's Some AND is within the specified bound". So this will only apply if both the minimum and maximum values are set in the schema.

I'm not sure of the best path forward here. I tried adjusting this, but then the NonZeroUXX tests failed. One option might be to specify add formats for the NonZeroXX types in the table above and then here to filter rather than find.

@davetayls
Copy link
Author

Thanks, I will take a look through them

@davetayls
Copy link
Author

@ahl not quite there,

I feel like we need to change the way that the NonZero types are applied because I presume we still want to use them when a format has been specified but that pattern doesn't fit with the formats array.

Can I just confirm that we want format: uint64, minimum: 1 to become NonZeroU64 rather than u64 as well as the corresponding 8,16,32 versions.

@ahl
Copy link
Collaborator

ahl commented Feb 11, 2025

Can I just confirm that we want format: uint64, minimum: 1 to become NonZeroU64 rather than u64 as well as the corresponding 8,16,32 versions.

Yes. I'm less certain about other schemas. That is to say: I'm not sure that { format: uint64: minimum: 7 } should be a NonZeroU64.

@davetayls
Copy link
Author

OK, thanks, I will stick to just applying it to minimum 1. Should be able to look at this at the weekend.

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.

Adding a "maximum" limit to an integer changes the inner Rust type
2 participants