newer-type crate

Ergonomic support for the newtype pattern in Rust, with automatic trait implementations.
The newtype pattern in Rust is useful for creating distinct types without runtime overhead. However, it often requires boilerplate code to re-implement traits of the inner type.
The newer-type crate provides a procedural macro #[implement(...)] to reduce that boilerplate by automatically implementing traits for your wrapper types.
Features
The #[implement(...)] macro currently supports automatic implementations for:
- User-defined traits annotated with
#[target] - Many traits from Rust
std, seenewer_type_stdcrate documentation
Example
Without newer-type (manual newtype definition)
;
With newer-type crate
# use ;
;
That's it! The selected traits are automatically implemented for you.
Examples using newer_type::traits
In order to implement traits defined in Rust's standard library for your newtype, there are empty definitions
in newer_type_std crate. You can pick up
traits to be implemented from it.
# use implement;
use ;
;
// now `MyVec` implements std::iter::IntoIterator, std::ops::Extend, std::cmp::{PartialEq, Eq}
Use Cases
This crate is particularly useful when:
- You want to create safe wrappers for existing types (e.g. for validation or domain modeling)
- You're working with abstract data structures like ASTs or instruction sets and want ergonomic iteration
- You frequently use the newtype pattern and want to avoid repetitive code
Installation
Add this to your Cargo.toml:
[]
= "0.1"
License
MIT