3 releases (breaking)
0.3.0 | Dec 18, 2024 |
---|---|
0.2.0 | Aug 21, 2024 |
0.1.0 | Jan 26, 2024 |
#297 in Procedural macros
199 downloads per month
19KB
377 lines
This crate contains a set of macros that can be used to generate strongly-typed fields for structs. The macros implement the newtype pattern, which allows the compiler to enforce type safety while still making it easy to convert the fields to and from their underlying representation.
Example
use typed_fields::number;
// Define a new type that is backed by an `i64`
number!(UserId);
// Create a new `UserId` from an `i64`
let id = UserId::new(42);
// Common traits like `Display` are automatically implemented for the type
println!("User ID: {}", id);
Dependencies
~0.2–1.3MB
~25K SLoC