facet-singularize 0.33.0

Fast, no-regex English singularization for the facet ecosystem
Documentation

facet-singularize

codecov crates.io documentation MIT/Apache-2.0 licensed Discord

facet-singularize

Fast, no-regex English singularization for the facet ecosystem.

Features

  • No regex - Uses simple string operations for performance in hot paths
  • No allocations with is_singular_of() - Perfect for deserialization matching
  • Handles common cases:
    • Irregular plurals (children → child, people → person)
    • -ies-y (dependencies → dependency)
    • -ves-f/-fe (wolves → wolf, knives → knife)
    • -es for sibilants (boxes → box, matches → match)
    • Simple -s removal (items → item)
  • no_std compatible

Usage

use facet_singularize::{singularize, is_singular_of};

// Convert plural to singular
assert_eq!(singularize("dependencies"), "dependency");
assert_eq!(singularize("children"), "child");
assert_eq!(singularize("boxes"), "box");

// Check if a word is the singular of another (allocation-free)
assert!(is_singular_of("dependency", "dependencies"));
assert!(is_singular_of("child", "children"));

Use Case

This crate is primarily used by facet-kdl for matching KDL node names to Rust field names:

#[derive(Facet)]
struct Config {
    #[facet(kdl::children)]
    dependencies: Vec<Dependency>,  // Matches "dependency" nodes
}

License

MIT OR Apache-2.0, at your option.

Sponsors

Thanks to all individual sponsors:

...along with corporate sponsors:

...without whom this work could not exist.

Special thanks

The facet logo was drawn by Misiasart.

License

Licensed under either of:

at your option.