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

Feature Request: Impl AsPrimitive for NonZero #335

Closed
foolishell opened this issue Sep 13, 2024 · 3 comments
Closed

Feature Request: Impl AsPrimitive for NonZero #335

foolishell opened this issue Sep 13, 2024 · 3 comments

Comments

@foolishell
Copy link

Background

I use async-graphql which depends on this crate on validation.
https://github.com/async-graphql/async-graphql/blob/master/src/validators/minimum.rs

I want to use NonZero Integers as well as normal integers.

Feature Request

impl AsPrimitive for NonZero integers

@cuviper
Copy link
Member

cuviper commented Sep 18, 2024

I use async-graphql which depends on this crate on validation.
https://github.com/async-graphql/async-graphql/blob/master/src/validators/minimum.rs

Given that AsPrimitive is lossy, I think it's quite dangerous to use for validation, even aside from NonZero. For example, minimum(&-1, 032) will return Ok!

@cuviper
Copy link
Member

cuviper commented Sep 18, 2024

Use-case aside -- we aren't currently implementing this for any non-primitive types, as I mentioned in #334 (comment). That's not necessarily a show-stopper, since the trait docs do mention newtypes too, but it would be an expansion from what we have now.

@foolishell
Copy link
Author

Thank you for telling me!
I'll close this issue.

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

No branches or pull requests

2 participants