Crate typed_fields

Source
Expand description

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);

Macros§

name
Generate a new type for a string
number
Generate a new type for a number
secret
Generate a new type for a secret
ulid
Generate a new type for a ULID
url
Generate a new type for a URL
uuid
Generate a new type for a UUID