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

FR: Associated constants on CommandOptionValue for min/max values #2402

Closed
khionu opened this issue Jan 3, 2025 · 0 comments · Fixed by #2415
Closed

FR: Associated constants on CommandOptionValue for min/max values #2402

khionu opened this issue Jan 3, 2025 · 0 comments · Fixed by #2415

Comments

@khionu
Copy link

khionu commented Jan 3, 2025

I'm writing a parser for a command registration system, and it would be nice to have the bounds for min/max value/length available as constants.

I've not tested these numbers yet, I took them from MDN with the assumption that JS is the reason 53-bit values were the bound.

While the *_length fields don't use CommandOptionValue, I think it would be appropriate to put STRING_RANGE there for discoverability. I'm recommending the use of Range here for a few reasons:

  1. Picking a name for "the minimum of the minimum value" etc is ugly
  2. Range::contains is convenient
  3. Range exposes the min/max as start and end fields, so the direct values are available
impl CommandOptionValue {
    const INTEGER_RANGE: Range<i64> = 
      -9007199254740991..=9007199254740991;
    const NUMBER_RANGE: Range<f64> =
      -9007199254740991.0..=9007199254740991.0;
    const STRING_RANGE: Range<u16> = 0..=6000;
}
Erk- added a commit that referenced this issue Jan 30, 2025
This commit adds associated types for the integer and floating point
range that is allowed.

It also adds a range that contains the allowed length of a string.

Closes #2402
@Erk- Erk- closed this as completed in #2415 Feb 9, 2025
@Erk- Erk- closed this as completed in 8e55599 Feb 9, 2025
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 a pull request may close this issue.

1 participant