Description
Implement BoundedString as a ValueObject in the primitives module.
Spec: BoundedString<const MIN: usize, const MAX: usize> via const generics
Implementation checklist
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
Description
Implement
BoundedStringas aValueObjectin theprimitivesmodule.Spec:
BoundedString<const MIN: usize, const MAX: usize>via const genericsImplementation checklist
src/primitives/boundedstring.rsValueObjecttrait#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]src/primitives/mod.rsandprelude# ExampleblockROADMAP.mdfrom ⬜ to ✅Implementation detail
Input / Output
BoundedStringuses const generics to encode the allowed length range at the type level.StringString(trimmed)Type declaration
Normalization
Trim surrounding whitespace.
Validation
MINand <=MAX.MINmust be <=MAX; enforce with a compile-time assertion or a runtime check that returns aCustomerror variant.Extra methods
None beyond the trait.
Notes
The
ValueObjectimpl will havetype Input = Stringandtype Output = String. Usechars().count()for length, not.len(), to count Unicode characters correctly.References