A Rust procedural macro for creating newtypes with built-in sanitization and validation guarantees.
Nutype is a Rust procedural macro that extends the newtype pattern by adding sanitization and validation constraints. It generates code that enforces these constraints at compile time and runtime, making it impossible to create invalid values—even during deserialization with serde. This helps ensure domain invariants are always upheld and reduces runtime errors.
Rust developers who use the newtype pattern to enforce business logic correctness, particularly those building domain-driven design (DDD) models or applications requiring strict data validation and sanitization.
Developers choose Nutype because it leverages Rust's type system to make invalid states unrepresentable, providing compile-time guarantees while seamlessly integrating with serde for serialization. Its unique selling point is combining sanitization (e.g., trimming strings) and validation (e.g., length limits) with automatic code generation for robust, type-safe newtypes.
Rust newtype with guarantees 🇺🇦 🦀
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Enforces validation and sanitization constraints through Rust's type system, making invalid states unrepresentable at compile-time, as demonstrated in the quick start with Username.
Integrates with serde for serialization and deserialization while preserving validation rules, ensuring data integrity even during I/O operations without manual checks.
Supports custom sanitizers, validators, and user-defined error types, allowing precise domain-specific error handling, such as custom regex or predicate validation.
Works with generic types and Higher-Ranked Trait Bounds, enabling constraints on complex data structures like non-empty collections, as shown in the examples.
Heavy reliance on procedural macros increases compile times, which can be a significant drawback for large projects or fast development cycles.
May enforce validation unnecessarily on already-verified data (e.g., from databases), impacting performance in high-throughput scenarios where speed is critical.
IDEs often provide limited support for procedural macros, reducing code completion and navigation features, which can slow down development and debugging.