Skip to main content

Crate typed_fields

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
Generates a new type for a string
number
Generates a new type for a number
path
Generates a new type for a path
secret
Generates a new type for a secret
ulid
Generates a new type for a ULID
url
Generates a new type for a URL
uuid
Generates a new type for a UUID