name-and-title

Crates.ioname-and-title
lib.rsname-and-title
version
sourcesrc
created_at2024-12-11 22:44:35.112272
updated_at2024-12-11 22:44:35.112272
descriptionA Rust library for representing personal names with optional titles, middle names/initials, and convenience macros.
homepage
repositoryhttps://github.com/klebs6/klebs-general
max_upload_size
id1480591
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`
size0
(klebs6)

documentation

https://docs.rs/name-and-title

README

name-and-title

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 Optional 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:

  • User Interfaces: Present names formally or informally in UI elements.
  • E-Commerce/CRM Systems: Store and retrieve customer names with optional titles.
  • Localization & Formatting: Integrate with translation or formatting systems to respect cultural naming conventions.
  • Data Serialization: Easily move between Rust structs and stored JSON data for user profiles.

License:

This project is licensed under the MIT license. See LICENSE for details.

Commit count: 248

cargo fmt