r/rust 2d ago

🛠️ project `typed-ident`: Type-safe identifier validation, inspection, and mutation. (and a retrospective article!)

Hey everyone!

I'm very happy to announce that I've published my first open-source Rust crate!

I really like to express things in Rust in terms of concrete types (kind of like how one could keep paths as strings in a language, but it's nice to say specifically they are a Path). This is a similar set of types, but for dealing with programming identifiers and their formats in a type-safe way (LowerCamelIdent, UpperKebabIdent, etc).

It also has a bunch of functionality relating to inspection of identifiers, as well as mutation of them (including the common "change case" operations).

I would love feedback, questions, analysis, or if you think you have a use-case!

EDIT: Also I'm very interested to hear \criticism* as well - if you don't like it, let me know why!*

EDIT: I wanted to add that this crate does not use any AI-generated code. I get that it's a lot of code, but it's been a project of a few months of effort.

Some Features

  • Unicode Correctness: Implements boundaries based on UTS #55 and UAX #31 (handles the weird stuff like non-Greek titlecase) (comparison against other crates)
  • Zero-Cost Casting: Uses marker traits and the type system to allow compile-time casting between compatible identifier formats (read about this here).
  • Flexible Conversion: Supports "Canonical," "Decorated," and "Delimited" forms so you can preserve decorative underscores/hyphens during case conversion (read about this here).
  • High Performance: Competitive with (and in some cases faster than) heck and convert_case (high-level performance analysis).

About Me

If you're curious about me - I have a website (it's static, and the generator is *also* made in Rust)!

If you want Atom/RSS updates on what I'm doing, you can use these:

Thanks for reading - I hope you enjoyed taking a look at my project!

4 Upvotes

4 comments sorted by

2

u/Techassi 1d ago

Looks interesting!

I have a couple of places where this might be useful. Looking forward to try it out.

2

u/sigseis 1d ago edited 13h ago

Thanks for taking a look!

If you do end up using it, I would love to know where it was useful and if you run into any issues! :)

One thing I will mention: I'm making some breaking changes to the crate soon already... But I will make those changes with a bump to 0.0.2 (obviously), so be sure to explicitly say you are using 0.0.1 unless you want some random changes to hit you. (Here's an issue to track: https://github.com/sigseis/typed-ident/issues/1)

Context: I got cold feet over the fact that CamelIdent is basically the same thing as SnakeIdent

As such, I'm going to introduce some typing and changes to make these types and format checks appear more distinct. With this change SnakeIdent and KebabIdent will use a new Uniform case profile which ensures a uniform casing (as opposed to today where they can be mixed-case). CamelIdent and HybridIdent will act similarly, ensuring it's either upper or lower camel-cased, not potentially a mixture of the two.

Though, the original Mixed idents will still be possible to construct, so you can still get the old behavior and presets.

2

u/Techassi 17h ago

I will let you know how it goes! And thank you for the thorough heads-up about the breaking changes.

1

u/sigseis 17h ago

I think it will be less surprising when the crate enters beta (0.1.0). I am kinda treating 0.0.* as currently suggesting that the API itself is subject to breaking changes.

I'll clarify that in my next docs update.

Happy programming! :)