typed-ident 0.0.2

Type-safe identifier validation, inspection, and mutation.
Documentation

typed-ident

A Rust crate for type-safe identifier validation, inspection, and mutation.

Alpha Software: The API is unstable and may contain breaking changes in any release. Do not depend on typed-ident for a stable public interface yet.

Unicode Standards

The Unicode-based identifier profiles and boundary calculations follow:

Example

The most common way to use this crate is through its predefined identifier presets. You can choose the preset that matches the syntax you want to enforce.

use typed_ident::core::fmt::*;
use typed_ident::presets::unicode::*;

// Validate the format of input to see that it matches expectations.
let identifier = UpperCamelIdent::new("HTTPServer")?;

// Look at all of the segments of the identifier.
println!("identifier segments:");
for segment in identifier.segments() {
    println!("* {segment:?}"); // [Chunk("HTTP"), Chunk("Server")]
}

// Convert to a different displayable format.
let lower_snake = identifier.as_lower_snake();
println!("as lower-snake: {lower_snake}"); // "http_server"

// Create a decorated identifier.
let decorated = identifier.with_circumfix("__", "__")?;
println!("with decoration: {decorated}"); // "__HTTPServer__"

Once constructed, identifiers can be inspected, converted, and mutated through their methods while preserving the type's validity guarantees.

If the provided presets do not match your requirements, you can define your own syntax.

When to Use

typed-ident is intended for values that represent programming identifiers and must obey a defined identifier syntax.

Use it when you need to:

  • Check that an input is a valid identifier
  • Distinguish between different identifier casing conventions at the type level
  • Inspect identifier boundaries, delimiters, or segments
  • Convert between different identifier casing conventions while preserving identifier semantics
  • Safely build or modify identifiers without accidentally producing invalid values

Typical use cases include:

  • Programming language implementations
  • Procedural macros and code generation
  • Compiler, formatter, or linter tooling
  • Schema, API, or serialization code that generates fields, types, or methods
  • Refactoring and rename tools

For ordinary strings that only need case conversion, use a general-purpose crate such as convert_case.

For URLs, REST paths, filesystem paths, or other domain-specific syntax, use a crate that understands that syntax instead.

Changelog

See CHANGELOG for release history.

Contributing

We welcome contributions!

Please read the CONTRIBUTING guide before contributing.

License

Licensed under either the Apache License, Version 2.0 or MIT license, at your option.