name!() { /* proc-macro */ }
Expand description
Generate a new type for a string
The name!
macro generates a new type that is backed by a String
. The new type implements
common traits like Display
and From<&str>
and From<String>
. The inner value can be
accessed using the get
method.
ยงExample
use typed_fields::name;
// Define a new type that is backed by a `String`
name!(Login);
// Create a new `UserId` from a `&str`
let id = Login::new("jdno");
// Common traits like `Display` are automatically implemented for the type
println!("Login: {}", id);