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

Add new type similar to AtLeastOne to enforce min/max size constraints and use it instead of Vecs in AdjustedDifficulty #8484

Open
arya2 opened this issue May 1, 2024 · 0 comments
Labels
A-rust Area: Updates to Rust code C-cleanup Category: This is a cleanup C-tech-debt Category: Code maintainability issues S-needs-triage Status: A bug report needs triage

Comments

@arya2
Copy link
Contributor

arya2 commented May 1, 2024

Motivation

There's repetitive code around taking a constant number of items from an iterator to collect into a Vec, and there are max size constraints that aren't currently enforced in AdjustedDifficulty methods.

It would be easier to maintain and verify correctness if we had a struct that handled this logic instead.

Design

Create a new type similar to AtLeastOne with a const generic for max size, which:

  • Calls take() to ensure the max size is enforced, and

Either:

  • Uses AtLeastOne as the inner type to check that there's at least one element, or
  • Accepts another const generic for min size and returns an error if there are fewer items in the iterator than the min size (optional)

Currently the minimum length for this use case is 1, so using AtLeastOne as the inner type would suffice.

@arya2 arya2 added A-rust Area: Updates to Rust code C-cleanup Category: This is a cleanup S-needs-triage Status: A bug report needs triage C-tech-debt Category: Code maintainability issues labels May 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-rust Area: Updates to Rust code C-cleanup Category: This is a cleanup C-tech-debt Category: Code maintainability issues S-needs-triage Status: A bug report needs triage
Projects
Status: New
Development

No branches or pull requests

1 participant