12 unstable releases (5 breaking)

Uses new Rust 2024

new 0.6.1 Mar 29, 2026
0.6.0 Dec 3, 2025
0.5.2 Aug 11, 2025
0.4.3 Jul 4, 2025
0.1.0 Jan 26, 2024

#1151 in Procedural macros

Download history 183/week @ 2025-12-07 400/week @ 2025-12-14 160/week @ 2025-12-21 90/week @ 2025-12-28 148/week @ 2026-01-04 352/week @ 2026-01-11 396/week @ 2026-01-18 304/week @ 2026-01-25 827/week @ 2026-02-01 924/week @ 2026-02-08 652/week @ 2026-02-15 416/week @ 2026-02-22 872/week @ 2026-03-01 1387/week @ 2026-03-08 1558/week @ 2026-03-15 1189/week @ 2026-03-22

5,048 downloads per month
Used in 5 crates (3 directly)

MIT/Apache

44KB
802 lines

🦀 typed-fields

Do you like strongly-typed structs?

typed-fields is a collection of macros that generate types following the newtype pattern. The following types are currently supported:

  • name! - a string-based type
  • number! - a number-based type
  • path! - a type for filesystem paths
  • secret! - a type for secrets (requires the secret feature)
  • ulid! - a type for ULIDs (requires the ulid feature)
  • url! - a type for URLs (requires the url feature)
  • uuid! - a type for UUIDs (requires the uuid feature)

Example

The following example showcases the number! macro, which generates a new type that is backed by an i64.

use typed_fields::number;

// Define a new type that is backed by an `i64`
number!(UserId);

fn main() {
    // 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);
}

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Dependencies

~0.1–3.5MB
~45K SLoC