Allow multiple names and associating static data per-string #52
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
First, apologies for the guerilla PR. I've been using the library for some time while thinking it'd be nice to have per-string data, so I eventually just decided to implement it for fun first and see if it's acceptable to merge back in second.
This refactors the internals of the crate to allow for multiple independent caches (whose ustrs/tokens are distinct types), closing #30, that may additionally choose to store their own datatype alongside the string's hash/length, deriving the data on first internment. The main implementations of global helpers like
string_cache_iterare also moved into the trait itself, so you can just sayDataless::string_cache_iter()orDataless::num_entries(), and the old global functions redirect to those.Because there's now a pervasive type parameter required / to maintain compatibility with existing code, I switched it up so
Ustris merely a typedef for a new internalInternedString<N>type using a dataless (()-storing) namespace. The idea is that anyone who wants more namespaces/data would define their own facade, like:I'll leave this as a draft PR for the moment as I look for other things to clean up / use it myself / eventually run through the benchmarks to see if there's any impact from the trait indirection. Let me know if there's anything you'd want changed or if this just doesn't seem like a good fit to merge in.