Nutype 0.7.0 adds conditional derives for Rust newtypes
Nutype 0.7.0 turned cfg_attr into a packaging win, letting Rust newtypes switch derives by build context instead of cloning wrapper types.

Conditional derives became Nutype’s cleanest answer to a familiar Rust headache: how to keep one newtype API aligned with different build targets, feature sets, and test configurations without multiplying wrapper types.
Nutype 0.7.0 landed on April 25, 2026, and its most visible change was cfg_attr support for derives. That matters because Nutype is not just a convenience macro. It is a proc macro crate that wraps the classic newtype pattern with sanitization and validation, then generates code that makes it impossible to instantiate a value without passing the checks. The crate also extends that protection into serde deserialization, which has made it attractive to teams that want domain rules enforced by the type system rather than scattered runtime guards.
With cfg_attr, the trait set can now follow the same conditional logic already used elsewhere in a crate. Rust’s conditional compilation model allows code to be enabled or disabled based on predicates such as target architecture, feature flags, and other compiler-set configuration options. Nutype 0.7.0 applies that idea directly to derives, so a library can expose one wrapper type and still shape its trait surface differently for different build contexts. That is a practical gain for crates that ship across multiple platforms or need feature-gated behavior to stay clean.
The release was presented as one of the project’s most-requested features, alongside a handful of smaller additions. That framing fits Nutype’s broader appeal. The crate has always lived at the intersection of correctness and developer experience, and the value has been in removing ceremony from invariant-heavy code, not in adding more abstraction for its own sake. Conditional derives push that philosophy further by reducing the pressure to duplicate type definitions just to satisfy a platform-specific trait bound.
The design also lines up with the crate’s long-standing caution around trait derivation. In a 2024 GitHub discussion, maintainer Serhii Potapov explained that Nutype keeps derives inside the macro and uses a whitelist of allowed traits to avoid implementations that could break invariants. That decision makes the new cfg_attr support feel less like a detour and more like the next step in the same strategy: keep the API expressive, but keep validation in control.
For Rust teams building APIs, data models, and validation-heavy services, the release is a reminder that compile-time guarantees do not have to come with rigid packaging. Nutype 0.7.0 made the crate fit more naturally into real-world build matrices, and that is exactly the kind of small macro improvement that removes real friction.
Know something we missed? Have a correction or additional information?
Submit a Tip

