Add non-empty string and collection types for API boundary validation#40
Add non-empty string and collection types for API boundary validation#40
Conversation
|
|
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #40 +/- ##
==========================================
+ Coverage 67.89% 75.89% +8.00%
==========================================
Files 6 7 +1
Lines 380 556 +176
==========================================
+ Hits 258 422 +164
- Misses 122 134 +12
Continue to review full report in Codecov by Sentry.
|
- Add nonempty dependency (v0.10.0) with serialize feature - Create non_empty module with NonEmptyString, TrimmedNonEmptyString - Re-export NonEmptyVec type alias for nonempty::NonEmpty - Add comprehensive unit tests for all types - Add rustdoc examples and usage documentation - Export types from lib.rs under non_empty feature flag Co-authored-by: emgrav <614975+emgrav@users.noreply.github.com>
Remove unstable doc_auto_cfg feature that was removed in Rust 1.92.0 Co-authored-by: emgrav <614975+emgrav@users.noreply.github.com>
The EmptyCollection variant was never used since NonEmptyVec uses the nonempty crate's own error handling Co-authored-by: emgrav <614975+emgrav@users.noreply.github.com>
Capitalize first word in error variant docs to follow Rust conventions Co-authored-by: emgrav <614975+emgrav@users.noreply.github.com>
|
@copilot We should ensure that we provide the full API surface of the nonempty crate and not just the newtype. F.x. also the Macro. Preferrably by simply reexporting it rather than reimplementing it. |
- Export NonEmpty type for full API surface access - Export nonempty! macro for ergonomic construction - Add module-level documentation example for macro usage - Add rustdoc example for macro usage - Keep NonEmptyVec type alias for convenient Vec-like usage Co-authored-by: emgrav <614975+emgrav@users.noreply.github.com>
Done. Re-exported the full
See commit c4fa4b2. |
API payloads need to reject empty strings and collections at deserialization boundaries, not in business logic. Current types allow deserializing empty values, pushing validation downstream.
Implementation
New types under
non_emptyfeature:NonEmptyString- Rejects empty strings during serde deserializationTrimmedNonEmptyString- Trims whitespace, rejects blank stringsNonEmptyVec<T>- Type alias fornonempty::NonEmpty<T>with serde supportNonEmptyError- Validation error enumRe-exported from
nonemptycrate:NonEmpty<T>- Full type with complete API surfacenonempty!macro - Ergonomic construction of non-empty collectionsBehavior:
Dependencies:
nonemptyv0.10.0 with serialize feature (no vulnerabilities)API surface:
FromStr,Display,Deref,Serialize,Deserializenonemptycrate API re-exported for advanced usageAdditional fix
Removed
doc_auto_cfgfeature (removed in Rust 1.92.0) that prevented doc builds.Original prompt
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.