Crates.io | name-and-title |
lib.rs | name-and-title |
version | |
source | src |
created_at | 2024-12-11 22:44:35.112272 |
updated_at | 2024-12-11 22:44:35.112272 |
description | A Rust library for representing personal names with optional titles, middle names/initials, and convenience macros. |
homepage | |
repository | https://github.com/klebs6/klebs-general |
max_upload_size | |
id | 1480591 |
Cargo.toml error: | TOML parse error at line 24, column 1 | 24 | autolib = false | ^^^^^^^ unknown field `autolib`, expected one of `name`, `version`, `edition`, `authors`, `description`, `readme`, `license`, `repository`, `homepage`, `documentation`, `build`, `resolver`, `links`, `default-run`, `default_dash_run`, `rust-version`, `rust_dash_version`, `rust_version`, `license-file`, `license_dash_file`, `license_file`, `licenseFile`, `license_capital_file`, `forced-target`, `forced_dash_target`, `autobins`, `autotests`, `autoexamples`, `autobenches`, `publish`, `metadata`, `keywords`, `categories`, `exclude`, `include` |
size | 0 |
name-and-title is a Rust library providing a strongly typed representation of a person's name, including an optional title, first name, middle name (or initial), and last name. It leverages builder patterns, serde
for serialization/deserialization, and convenience macros to simplify name construction and usage in your applications.
Key Features:
Flexible Name Representation:
Supports Option
al title, middle name/initials, and fully typed FirstName
, MiddleName
, LastName
structures.
Convenience Macros:
Quickly convert string literals or characters into FirstName
, LastName
, and Middle
variants. For example:
let name = PersonNameBuilder::default()
.first("Alice")
.middle("Marie") // or .middle('M')
.last("Smith")
.build()
.unwrap();
Optional Title with Defaults:
The title
field is fully optional. If omitted, it defaults to None
, allowing for simple "first last" formats.
Integration with serde
:
Serialize and deserialize names to/from JSON and other formats. This makes it easy to store and retrieve user information in databases, files, or transmit over networks.
FromStr
and Display
for Titles:
Person titles such as "Mr.", "Mrs.", "Dr." can be parsed from strings and displayed back easily, including custom or unknown titles.
Example:
use name_and_title::{PersonNameBuilder, PersonTitle};
fn main() {
let name = PersonNameBuilder::default()
.title(PersonTitle::Dr)
.first("John")
.middle("Q")
.last("Public")
.build()
.expect("Failed to build PersonName");
println!("Full name: {}", name.full_name());
// Outputs: "Dr. John Q Public"
// Without title and middle:
let simple_name = PersonNameBuilder::default()
.first("Jane")
.last("Doe")
.build()
.expect("Failed to build PersonName");
println!("Simple name: {}", simple_name.full_name());
// Outputs: "Jane Doe"
}
Use Cases:
License:
This project is licensed under the MIT license. See LICENSE for details.