Skip to content

Add BoundedString (primitives) #67

@vhrcgcom

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

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