typed-ident

This project exists to allow one to work with programming identifiers in a more feature-complete way than normal Ident types.

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__"

For more information, check either the crates page, or read the project documentation.

A lot of the things I work on are code generators. There was no existing crate that satisfied all of my requirements, and it’s important to get the requirements right before you start generating a lot of code.

In particular, the following two things were important to me.

  • The ability to constrain user input to some specific kind of cased format (e.g. UpperCamel or lower_snake).
  • The ability to safely convert between cases without losing important information or invalidating the identifier.
  • The ability to make small mutations to existing identifiers (like prefixing, suffixing, etc).
  • The ability to inspect the structure of an identifier (its parts, delimiters, words, etc).

One could argue that case conversion is possible today, but if I had to nit-pick none of them quite work exactly as I want (and none of them allow for specific configurations to make them work exactly how I want).

The specific things lacking from other libraries were:

  • Handling of capitalization cased conversion for letters which uppercase to multiple letters instead of just one (ß -> SS -> Ss).
  • Boundary detection satisfying Unicode Technical Standard #55.
  • Not all of the mutation properties were safely present (such as suffixing or prefixing) while maintaining format invariants.
  • Most APIs either had no identifier inspection functions, or they were limited or detached from the type structure.

ANNOUNCEMENTS

view all →

typed-ident: v0.0.2 Release

Today marks the official release of the v0.0.2 version of `typed-ident`! This update fixes several issues with the initial API, and improves documentation to make understanding what the crate is capable of a little easier. There’s still a bit more to go before I’ll be happy marking this as a beta, but this release was important to get out quickly.
Read More...

typed-ident: v0.0.1 Release

Today marks the official release of the v0.0.1 version of `typed-ident`! This is a project that initially started out as just some internal utility library, but needed to be factored out for formally releasing another project that I’m working on. In the process, I ended up doing a bunch of work to make it as complete of an implementation as possible. There’s already some things I’m not a fan of, so a v0.0.2 is scheduled to release very soon. However, if you would like to play around with this early alpha, you can on crates.io now.
Read More...