Skip to content

Conversation

@syszery
Copy link
Contributor

@syszery syszery commented Nov 5, 2025

Motivation

This PR fixes #8484 by introducing the new type, Bounded, which extends the existing AtLeastOne type to enforce both minimum and maximum size constraints. This ensures that collections in AdjustedDifficulty have a controlled size, improving correctness and safety compared to plain Vecs.

Solution

  • Introduce pub struct Bounded<T, const MAX: usize> as a wrapper around AtLeastOne<T>.
  • Bounded enforces a lower bound of at least one element (inherited from AtLeastOne) and adds an upper bound (MAX).
  • Replace Vecs in AdjustedDifficulty with Bounded where constrained numbers of elements are expected.

PR Checklist

  • The PR name is suitable for the release notes.
  • The PR follows the contribution guidelines.
  • The library crate changelogs are up to date.
  • The solution is tested.
  • The documentation is up to date.

@github-actions github-actions bot added the C-feature Category: New features label Nov 5, 2025
@arya2
Copy link
Contributor

arya2 commented Nov 11, 2025

It might be better to use bounded-vec instead of rolling our own.

@syszery syszery force-pushed the feature/bounded-vec-constraint branch from 8ba6317 to 3463d3c Compare November 12, 2025 19:23
@syszery
Copy link
Contributor Author

syszery commented Nov 12, 2025

Update

Hi @arya2, thanks for the suggestion. I’ve reworked the PR to use the bounded_vec crate.

Here’s what I did:

  • Switched from the custom Bounded and AtLeastOne to the bounded-vec crate.
  • Refactored AtLeastOne to be a type alias for BoundedVec.
  • Updated all affected modules and tests to use BoundedVec.

The rebase is done, and I’ve confirmed that all tests, Clippy, and formatting checks passed. Let me know if you have any feedback!

@syszery syszery marked this pull request as ready for review November 12, 2025 19:36
@arya2 arya2 added do-not-merge Tells Mergify not to merge this PR and removed do-not-merge Tells Mergify not to merge this PR labels Nov 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

C-feature Category: New features

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

2 participants