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.

You can add the dependency by editing your Cargo.toml:

[dependencies]
typed-ident = "0.0.2"

Or by using cargo add:

cargo add typed-ident

Or update by using cargo update:

cargo update -p typed-ident

This release, new case profiles were added to represent either an Upper* or Lower* identifier format (but not a mix).

In v0.0.1, there was only {Format}Ident, Lower{Format}Ident, and Upper{Format}Ident (e.g. CamelIdent, for instance). The issue with this is you either give up all strict casing ({Format}Ident), or you have to be very explicit about your casing (Lower{Format}Ident, Upper{Format}Ident). There was no way to say that you wanted strict casing, but not specifically which strict casing.

The new Cased{Format}Ident type aliases make this possible.

use typed_ident::presets::unicode::*;

// Strictly Upper- or Lower- cased identifiers parse.
assert!(CasedCamelIdent::new("lowerCamel").is_ok());
assert!(CasedCamelIdent::new("UpperCamel").is_ok());

// However, a mixture will not parse.
//
// Use a less strict type if this is what you want (`CamelIdent`).
assert!(CasedCamelIdent::new("lowerCamel_UpperCamel").is_err());
assert!(CamelIdent::new("lowerCamel_UpperCamel").is_ok());

The performance of typed-ident was already pretty good, however the v0.0.2 release makes it even better by having more efficient lookups for titlecase and Greek titlecase letters.

This was accomplished by rolling our own code generation utility specifically for this crate. It makes more sense to do this rather than depend on some external crate, because of how specific and weird our needs are.

Additionally this also has greatly improved the Strict profile - which prior depended on unicode-general-category, but now knows how to do the strict formatting check much more efficiently.

To see how this was accomplished, look at the internal generator project that exists alongside typed-ident.

In the v0.0.1 release, one thing that was pretty annoying was how we interacted with the FragmentBuf API.

You had to call specific methods, with specific names, based on the input you wanted to provide. This led to two things; an explosion of combinations of methods on FragmentBuf, annoying developer ergonomics where the function you called depended on the input.

let mut buffer = UpperCamelFragmentBuf::new();
assert!(buffer.push_bounded_str("String").is_ok());
assert!(buffer.push_bounded_fragment(UpperCamelFragment::new("Fragment")?).is_ok());
assert!(buffer.push_bounded('C').is_ok()); // character

To fix this, we introduced a new trait; IntoIntermediate.

The IntoIntermediate trait is a crate-private trait, which represents a cast into a type that could be casted to be represented as a Fragment. This, it turns out, is a powerful improvement, because instead of having one function per input, we can now just have a single function whose input type must implement IntoIntermediate.

So now, the above code can be accomplished in a much simpler way:

let mut buffer = UpperCamelFragmentBuf::new();
assert!(buffer.push_bounded("String").is_ok());
assert!(buffer.push_bounded(UpperCamelFragment::new("Fragment")?).is_ok());
assert!(buffer.push_bounded('C').is_ok()); // character

Here’s a list of all of the functions impacted by this change in FragmentBuf:

  • insert
  • insert_fragment (Removed)
  • insert_str (Removed)
  • insert_bounded
  • insert_bounded_with
  • insert_bounded_fragment (Removed)
  • insert_bounded_fragment_with (Removed)
  • insert_bounded_str (Removed)
  • insert_bounded_str_with (Removed)
  • insert_delimited
  • insert_delimited_with
  • insert_delimited_fragment (Removed)
  • insert_delimited_fragment_with (Removed)
  • insert_delimited_str (Removed)
  • insert_delimited_str_with (Removed)
  • push
  • push_fragment (Removed)
  • push_str (Removed)
  • push_bounded
  • push_bounded_with
  • push_bounded_fragment (Removed)
  • push_bounded_fragment_with (Removed)
  • push_bounded_str (Removed)
  • push_bounded_str_with (Removed)
  • push_delimited
  • push_delimited_with
  • push_delimited_fragment (Removed)
  • push_delimited_fragment_with (Removed)
  • push_delimited_str (Removed)
  • push_delimited_str_with (Removed)

Similar improvements to the API were implemented on Fragment and Ident:

  • join
  • join_str (Removed)
  • join_str_with (Removed)
  • join_with
  • replace
  • replace_str (Removed)
  • with_circumfix
  • with_circumfix_str (Removed)
  • with_prefix
  • with_prefix_str (Removed)
  • with_suffix
  • with_suffix_str (Removed)

While the documentation is still not perfect, there has been a very finely detailed pass on improving all of the documentation within the entire crate.

Of note, one of the places where documentation has improved greatly is with the commonly-used type aliases for specific identifier configuration presets provided by this crate.

Take a look at the CamelIdent documentation for an example, and compare that to the prior documentation.

This is certainly not the only documentation improvement - as mentioned the whole crate has had all of its documentation re-written. See the full documentation for more.

There’s a few other minor changes worth noting:

  • IdentBuf has been fully removed (it is a difficult to use type, and doesn’t really make a lot of sense).
  • Added plain-form formatting operations which don’t check the validity of the produced identifier.

The project is still not ready for beta, the next release is already planned, and progress can be tracked from the v0.0.3 milestone page.

Thanks for reading, and I hope these improvements are useful for you!

← Previous Announcement
typed-ident: v0.0.1 Release