Skip to content

Add BoundedString (primitives) #67

Description

@vhrcgcom

Description

Implement BoundedString as a ValueObject in the primitives module.

Spec: BoundedString<const MIN: usize, const MAX: usize> via const generics

Implementation checklist

  • Create src/primitives/boundedstring.rs
  • Implement ValueObject trait
  • Add #[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
  • Export from src/primitives/mod.rs and prelude
  • Unit tests: valid input · empty input · invalid format · normalisation
  • Doc comment with # Example block
  • Update status in ROADMAP.md from ⬜ to ✅

Implementation detail

Input / Output

BoundedString uses const generics to encode the allowed length range at the type level.

Type
Input String
Output String (trimmed)

Type declaration

pub struct BoundedString<const MIN: usize, const MAX: usize>(String);

Normalization

Trim surrounding whitespace.

Validation

  • Length in Unicode characters (not bytes) after trimming must be >= MIN and <= MAX.
  • MIN must be <= MAX; enforce with a compile-time assertion or a runtime check that returns a Custom error variant.

Extra methods

None beyond the trait.

Notes

The ValueObject impl will have type Input = String and type Output = String. Use chars().count() for length, not .len(), to count Unicode characters correctly.

References

Activity

  1. changed the title [-]feat(primitives): BoundedString[/-] [+]Add BoundedString (primitives)[/+] on Apr 17, 2026
  2. linked a pull request that will close this issueAdd primitives module (v0.3.0) #84on Apr 20, 2026
  3. added a commit that references this issue on Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or improvement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions